Merge pull request #2098 from evincarofautumn/fix-gchandle-assert
[mono.git] / mcs / class / System.Web / System.Web / StaticFileHandler.cs
index 224fab57e5720dd00d93a8c0243421753d96c361..810f24c564439a5a3644839e418d5be541de8632 100644 (file)
@@ -5,6 +5,7 @@
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com)
 //
 // (C) 2002 Ximian, Inc (http://www.ximian.com)
+// (C) 2003-2009 Novell, Inc (http://novell.com)
 //
 
 //
@@ -32,22 +33,15 @@ using System;
 using System.Globalization;
 using System.IO;
 using System.Web.Util;
+using System.Web.Hosting;
 
 namespace System.Web
 {
        class StaticFileHandler : IHttpHandler
        {
-               static bool runningWindows = RunningOnWindows ();
-
-               static bool RunningOnWindows ()
-               {
-                       int pid = (int)Environment.OSVersion.Platform;
-                       return (pid != 4 && pid != 128);
-               }
-
                static bool ValidFileName (string fileName)
                {
-                       if (!runningWindows)
+                       if (!RuntimeHelpers.RunningOnWindows)
                                return true;
 
                        if (fileName == null || fileName.Length == 0)
@@ -60,40 +54,41 @@ namespace System.Web
                {
                        HttpRequest request = context.Request;
                        HttpResponse response = context.Response;
+
+                       if (HostingEnvironment.HaveCustomVPP) {
+                               VirtualFile vf = null;
+                               VirtualPathProvider vpp = HostingEnvironment.VirtualPathProvider;
+                               string vpath = request.FilePath;
+                               
+                               if (vpp.FileExists (vpath))
+                                       vf = vpp.GetFile (vpath);
+
+                               if (vf == null)
+                                       throw new HttpException (404, "Path '" + vpath + "' was not found.", vpath);
+
+                               response.ContentType = MimeTypes.GetMimeType (vpath);
+                               response.TransmitFile (vf, true);
+                               return;
+                       }
+                       
                        string fileName = request.PhysicalPath;
                        FileInfo fi = new FileInfo (fileName);
                        if (!fi.Exists || !ValidFileName (fileName))
-                               throw new HttpException (404, "File '" + request.FilePath + "' not found.");
+                               throw new HttpException (404, "Path '" + request.FilePath + "' was not found.", request.FilePath);
 
                        if ((fi.Attributes & FileAttributes.Directory) != 0) {
                                response.Redirect (request.Path + '/');
                                return;
                        }
-
+                       
                        string strHeader = request.Headers ["If-Modified-Since"];
                        try {
                                if (strHeader != null) {
                                        DateTime dtIfModifiedSince = DateTime.ParseExact (strHeader, "r", null);
                                        DateTime ftime;
-#if TARGET_JVM
-                                       try 
-                                       {
-                                               ftime = fi.LastWriteTime.ToUniversalTime ();
-                                       } 
-                                       catch (NotSupportedException) 
-                                       {
-                                               // The file is in a WAR, it might be modified with last redeploy.
-                                               try {
-                                                       ftime = (DateTime) AppDomain.CurrentDomain.GetData (".appStartTime");
-                                               }
-                                               catch {
-                                                       ftime = DateTime.MaxValue;
-                                               }
-                                       }
-#else
                                        ftime = fi.LastWriteTime.ToUniversalTime ();
-#endif
                                        if (ftime <= dtIfModifiedSince) {
+                                               response.ContentType = MimeTypes.GetMimeType (fileName);
                                                response.StatusCode = 304;
                                                return;
                                        }
@@ -103,7 +98,6 @@ namespace System.Web
                        try {
                                DateTime lastWT = fi.LastWriteTime.ToUniversalTime ();
                                response.AddHeader ("Last-Modified", lastWT.ToString ("r"));
-
                                response.ContentType = MimeTypes.GetMimeType (fileName);
                                response.TransmitFile (fileName, true);
                        } catch (Exception) {