Author: mhabersack
Date: 2008-02-07 08:18:35 -0500 (Thu, 07 Feb 2008)
New Revision: 95135

Modified:
   trunk/mcs/class/System.Web/System.Web.Compilation/BuildManager.cs
   trunk/mcs/class/System.Web/System.Web.Compilation/ChangeLog
   trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
   trunk/mcs/class/System.Web/System.Web.UI/PageHandlerFactory.cs
   trunk/mcs/class/System.Web/System.Web/ChangeLog
   trunk/mcs/class/System.Web/System.Web/HttpApplication.cs
   trunk/mcs/class/System.Web/System.Web/HttpContext.cs
   trunk/mcs/class/System.Web/System.Web/HttpException.cs
   trunk/mcs/class/System.Web/System.Web/StaticFileHandler.cs
Log:
2008-02-07  Marek Habersack  <[EMAIL PROTECTED]>

        * BuildManager.cs: check for virtualPath existence before
        attempting to compile the assemblies. Fixes bug #359465
2008-02-07  Marek Habersack  <[EMAIL PROTECTED]>

        * HttpException.cs: moved several strings to constants, for easier
        maintenance. 
        Added 3 new constructors which let the caller to set the exception
        description.
        The Description property is now settable.
        The stack trace at the bottom of the file is written after the
        terminating </html>, inside a HTML comment. Format changed to
        match MS.NET.
        Error 404 is handled in a special way, to match the output with
        MS.NET.

        * HttpContext.cs, StaticFileHandler.cs, HttpApplication.cs: use
        the new HttpException constructor for 404.
2008-02-07  Marek Habersack  <[EMAIL PROTECTED]>

        * PageHandlerFactory.cs: call PageParser.GetCompiledPageInstance
        only - that method calls the appropriate APIs for 1.1 and 2.0
        profiles.


Modified: trunk/mcs/class/System.Web/System.Web/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web/ChangeLog     2008-02-07 13:17:12 UTC 
(rev 95134)
+++ trunk/mcs/class/System.Web/System.Web/ChangeLog     2008-02-07 13:18:35 UTC 
(rev 95135)
@@ -1,3 +1,19 @@
+2008-02-07  Marek Habersack  <[EMAIL PROTECTED]>
+
+       * HttpException.cs: moved several strings to constants, for easier
+       maintenance. 
+       Added 3 new constructors which let the caller to set the exception
+       description.
+       The Description property is now settable.
+       The stack trace at the bottom of the file is written after the
+       terminating </html>, inside a HTML comment. Format changed to
+       match MS.NET.
+       Error 404 is handled in a special way, to match the output with
+       MS.NET.
+
+       * HttpContext.cs, StaticFileHandler.cs, HttpApplication.cs: use
+       the new HttpException constructor for 404.
+
 2008-02-07  Vladimir Krasnov  <[EMAIL PROTECTED]>
 
        * HttpResponse.cs: fixed AddHeadersNoCache, removed date_header since

Modified: trunk/mcs/class/System.Web/System.Web/HttpApplication.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/HttpApplication.cs    2008-02-07 
13:17:12 UTC (rev 95134)
+++ trunk/mcs/class/System.Web/System.Web/HttpApplication.cs    2008-02-07 
13:18:35 UTC (rev 95135)
@@ -946,9 +946,9 @@
 #endif
                        } catch (FileNotFoundException fnf){
                                if (context.Request.IsLocal)
-                                       ProcessError (new HttpException (404, 
String.Format ("File not found {0}", fnf.FileName), fnf));
+                                       ProcessError (new HttpException (404, 
String.Format ("File not found {0}", fnf.FileName), fnf, 
context.Request.FilePath));
                                else
-                                       ProcessError (new HttpException (404, 
"File not found: " + Path.GetFileName (fnf.FileName)));
+                                       ProcessError (new HttpException (404, 
"File not found: " + Path.GetFileName (fnf.FileName), 
context.Request.FilePath));
                        } catch (DirectoryNotFoundException dnf){
                                if (!context.Request.IsLocal)
                                        dnf = null; // Do not "leak" real path 
information

Modified: trunk/mcs/class/System.Web/System.Web/HttpContext.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/HttpContext.cs        2008-02-07 
13:17:12 UTC (rev 95134)
+++ trunk/mcs/class/System.Web/System.Web/HttpContext.cs        2008-02-07 
13:18:35 UTC (rev 95135)
@@ -609,8 +609,7 @@
                {
                        filePath = UrlUtils.Combine (Request.BaseVirtualDir, 
filePath);
                        if (!StrUtils.StartsWith (filePath, 
HttpRuntime.AppDomainAppVirtualPath))
-                               throw new HttpException (404, "The virtual path 
'" + filePath +
-                                       "' maps to another application.");
+                               throw new HttpException (404, "The virtual path 
'" + filePath + "' maps to another application.", filePath);
 
                        Request.SetCurrentExePath (filePath);
                        // A null pathInfo or queryString is ignored and 
previous values remain untouched

Modified: trunk/mcs/class/System.Web/System.Web/HttpException.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/HttpException.cs      2008-02-07 
13:17:12 UTC (rev 95134)
+++ trunk/mcs/class/System.Web/System.Web/HttpException.cs      2008-02-07 
13:18:35 UTC (rev 95135)
@@ -47,7 +47,14 @@
 #endif
        public class HttpException : ExternalException
        {
+               const string DEFAULT_DESCRIPTION_TEXT = "Error processing 
request.";
+               const string BOTTOM_EXCEPTION_FORMAT = "<!--\r\n[{0}]: 
{1}\r\n-->\r\n";
+               const string ERROR_404_DESCRIPTION = "The resource you are 
looking for (or one of its dependencies) could have been removed, had its name 
changed, or is temporarily unavailable.  Please review the following URL and 
make sure that it is spelled correctly.";
+               
                int http_code = 500;
+               string resource_name;
+               string description;
+               
                const string errorStyleFonts = "\"Verdana\",\"DejaVu 
Sans\",sans-serif";
                
                public HttpException ()
@@ -69,6 +76,16 @@
                        http_code = httpCode;
                }
 
+               internal HttpException (int httpCode, string message, string 
resourceName) : this (httpCode, message)
+               {
+                       resource_name = resourceName;
+               }
+
+               internal HttpException (int httpCode, string message, string 
resourceName, string description) : this (httpCode, message, resourceName)
+               {
+                       this.description = description;
+               }
+               
 #if NET_2_0
                protected HttpException (SerializationInfo info, 
StreamingContext context)
                        : base (info, context)
@@ -101,6 +118,12 @@
                        http_code = httpCode;
                }
 
+               public HttpException (int httpCode, string message, Exception 
innerException, string resourceName)
+                       : this (httpCode, message, innerException)
+               {
+                       resource_name = resourceName;
+               }
+               
                public string GetHtmlErrorMessage ()
                {
                        try {
@@ -120,7 +143,19 @@
                }
 
                internal virtual string Description {
-                       get { return "Error processing request."; }
+                       get {
+                               if (description != null)
+                                       return description;
+
+                               return DEFAULT_DESCRIPTION_TEXT;
+                       }
+                       
+                       set {
+                               if (value != null && value.Length > 0)
+                                       description = value;
+                               else
+                                       description = DEFAULT_DESCRIPTION_TEXT;
+                       }
                }
 
                void WriteFileTop (StringBuilder builder, string title)
@@ -147,14 +182,15 @@
                                "</style></head><body><h1>Server Error in '{0}' 
Application</h1><hr style=\"color: silver\"/>",
                                HtmlEncode 
(HttpRuntime.AppDomainAppVirtualPath));
                }
-
-               void WriteFileBottom (StringBuilder builder, string trace1, 
string trace2)
+               
+               void WriteFileBottom (StringBuilder builder, Exception ex1, 
Exception ex2)
                {
-                       if (trace1 != null)
-                               builder.AppendFormat 
("<![CDATA[\r\n{0}\r\n]]>\r\n", HttpUtility.HtmlEncode (trace1));
-                       if (trace2 != null)
-                               builder.AppendFormat 
("<![CDATA[\r\n{0}\r\n]]>\r\n", HttpUtility.HtmlEncode (trace2));
-                       builder.AppendFormat ("<hr style=\"color: 
silver\"/>{0}</body></html>\r\n", DateTime.UtcNow);
+                       builder.Append ("<hr style=\"color: silver\"/>");
+                       builder.AppendFormat ("<strong>Version information: 
</strong> Mono Version: {0}; ASP.NET Version: {0}</body></html>\r\n", 
Environment.Version);
+                       if (ex1 != null)
+                               builder.AppendFormat (BOTTOM_EXCEPTION_FORMAT, 
ex1.GetType (), ex1.ToString ());
+                       if (ex2 != null)
+                               builder.AppendFormat (BOTTOM_EXCEPTION_FORMAT, 
ex2.GetType (), ex2.ToString ());
                }
 
                string GetCustomErrorDefaultMessage ()
@@ -218,23 +254,28 @@
 
                        StringBuilder builder = new StringBuilder ();
                        WriteFileTop (builder, String.Format ("Error{0}", 
http_code != 0 ? " " + http_code : String.Empty));
-                       builder.AppendFormat ("<h2><em>{0}</em></h2>\r\n", 
HtmlEncode (ex.Message));
-                       builder.AppendFormat ("<p><strong>Description: 
</strong>{0}</p>\r\n", HtmlEncode (Description));
-                       builder.Append ("<p><strong>Error Message: </strong>");
+                       builder.Append ("<h2><em>");
+                       if (http_code == 404)
+                               builder.Append ("The resource cannot be 
found.");
+                       else
+                               builder.AppendFormat (HtmlEncode (ex.Message));
+                       builder.Append ("</em></h2>\r\n<p><strong>Description: 
</strong>");
+                       
                        if (http_code != 0)
                                builder.AppendFormat ("HTTP {0}. ", http_code);
-                       builder.AppendFormat ("{0}: {1}\r\n</p>\r\n", 
ex.GetType ().FullName, HtmlEncode (ex.Message));
+                       builder.Append (http_code == 404 ? 
ERROR_404_DESCRIPTION : HtmlEncode (Description));
+                       builder.Append ("</p>\r\n");
 
-                       if (baseEx != null) {
-                               builder.AppendFormat ("<p><strong>Stack Trace: 
</strong></p>");
+                       if (resource_name != null && resource_name.Length > 0)
+                               builder.AppendFormat ("<p><strong>Resource URL: 
</strong>{0}</p>\r\n", resource_name);
+                       
+                       if (baseEx != null && http_code != 404) {
+                               builder.Append ("<p><strong>Stack Trace: 
</strong></p>");
                                builder.Append ("<table summary=\"Stack Trace\" 
class=\"sampleCode\">\r\n<tr><td>");
                                WriteTextAsCode (builder, baseEx.ToString ());
                                builder.Append ("</td></tr>\r\n</table>\r\n");
                        }
-                       WriteFileBottom (builder,
-                                        this.ToString (),
-                                        null
-                       );
+                       WriteFileBottom (builder, ex, null);
                        
                        return builder.ToString ();
                }
@@ -285,7 +326,7 @@
 
                        WriteFileBottom (
                                builder,
-                               exc.ToString (),
+                               exc,
                                null
                        );
                        

Modified: trunk/mcs/class/System.Web/System.Web/StaticFileHandler.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web/StaticFileHandler.cs  2008-02-07 
13:17:12 UTC (rev 95134)
+++ trunk/mcs/class/System.Web/System.Web/StaticFileHandler.cs  2008-02-07 
13:18:35 UTC (rev 95135)
@@ -63,7 +63,7 @@
                        string fileName = request.PhysicalPath;
                        FileInfo fi = new FileInfo (fileName);
                        if (!fi.Exists || !ValidFileName (fileName))
-                               throw new HttpException (404, "Path '" + 
request.FilePath + "' was not found.");
+                               throw new HttpException (404, "Path '" + 
request.FilePath + "' was not found.", request.FilePath);
 
                        if ((fi.Attributes & FileAttributes.Directory) != 0) {
                                response.Redirect (request.Path + '/');

Modified: trunk/mcs/class/System.Web/System.Web.Compilation/BuildManager.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.Compilation/BuildManager.cs   
2008-02-07 13:17:12 UTC (rev 95134)
+++ trunk/mcs/class/System.Web/System.Web.Compilation/BuildManager.cs   
2008-02-07 13:18:35 UTC (rev 95135)
@@ -263,7 +263,9 @@
                        // Get the Type.
                        Type type = GetCompiledType (virtualPath);
                        if (type == null)
-                               throw new HttpException ("Instance creation 
failed for virtual path '" + virtualPath + "'.");
+                               //throw new HttpException ("Instance creation 
failed for virtual
+                               //path '" + virtualPath + "'.");
+                               return null;
                        
                        if (!requiredBaseType.IsAssignableFrom (type)) {
                                string msg = String.Format ("Type '{0}' does 
not inherit from '{1}'.",
@@ -774,9 +776,35 @@
                        builders.Add (CreateAssemblyBuilder (assemblyBaseName, 
virtualPath, buildItem));
                        buildItem.StoreCodeUnit ();
                }
+
+               static void AssertVirtualPathExists (string virtualPath)
+               {
+                       string realpath;
+                       bool fakePath;
+                       
+                       if (StrUtils.StartsWith (virtualPath, 
FAKE_VIRTUAL_PATH_PREFIX)) {
+                               realpath = virtualPath.Substring 
(FAKE_VIRTUAL_PATH_PREFIX.Length);
+                               fakePath = true;
+                       } else {
+                               HttpContext ctx = HttpContext.Current;
+                               HttpRequest req = ctx != null ? ctx.Request : 
null;
+
+                               if (req == null)
+                                       throw new HttpException ("Missing 
context, cannot continue.");
+
+                               realpath = req.MapPath (virtualPath);
+                       }
+
+                       if (!File.Exists (realpath) && !Directory.Exists 
(realpath))
+                               throw new HttpException (404,
+                                                        "The file '" + 
virtualPath + "' does not exist.",
+                                                        fakePath ? 
Path.GetFileName (realpath) : virtualPath);
+               }
                
                static void BuildAssembly (string virtualPath)
                {
+                       AssertVirtualPathExists (virtualPath);
+                       
                        object ticket;
                        bool acquired;
                        string virtualDir = GetVirtualPathDirectory 
(virtualPath);

Modified: trunk/mcs/class/System.Web/System.Web.Compilation/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.Compilation/ChangeLog 2008-02-07 
13:17:12 UTC (rev 95134)
+++ trunk/mcs/class/System.Web/System.Web.Compilation/ChangeLog 2008-02-07 
13:18:35 UTC (rev 95135)
@@ -1,3 +1,8 @@
+2008-02-07  Marek Habersack  <[EMAIL PROTECTED]>
+
+       * BuildManager.cs: check for virtualPath existence before
+       attempting to compile the assemblies. Fixes bug #359465
+
 2008-02-06  Marek Habersack  <[EMAIL PROTECTED]>
 
        * GenericBuildProvider.cs: GetGeneratedType may return a type even

Modified: trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/ChangeLog  2008-02-07 13:17:12 UTC 
(rev 95134)
+++ trunk/mcs/class/System.Web/System.Web.UI/ChangeLog  2008-02-07 13:18:35 UTC 
(rev 95135)
@@ -1,3 +1,9 @@
+2008-02-07  Marek Habersack  <[EMAIL PROTECTED]>
+
+       * PageHandlerFactory.cs: call PageParser.GetCompiledPageInstance
+       only - that method calls the appropriate APIs for 1.1 and 2.0
+       profiles.
+
 2008-02-06  Vladimir Krasnov  <[EMAIL PROTECTED]>
 
        * Control.cs: fixed ResolveClientUrlInternal for portal url prefixes

Modified: trunk/mcs/class/System.Web/System.Web.UI/PageHandlerFactory.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/PageHandlerFactory.cs      
2008-02-07 13:17:12 UTC (rev 95134)
+++ trunk/mcs/class/System.Web/System.Web.UI/PageHandlerFactory.cs      
2008-02-07 13:18:35 UTC (rev 95135)
@@ -37,11 +37,7 @@
        {
                public virtual IHttpHandler GetHandler (HttpContext context, 
string requestType, string url, string path)
                {
-#if NET_2_0 && !TARGET_JVM
-                       return BuildManager.CreateInstanceFromVirtualPath (url, 
typeof (IHttpHandler)) as IHttpHandler;
-#else
                        return PageParser.GetCompiledPageInstance (url, path, 
context);
-#endif
                }
 
                public virtual void ReleaseHandler (IHttpHandler handler)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to