2009-06-04 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web / HttpException.cs
index 804a720455c27ea4edfc8b56a3fbbfa4e86f454b..6385ffe7cb325273c38e77e17cc1d297dcaada43 100644 (file)
@@ -133,11 +133,15 @@ namespace System.Web
                {
                        try {
                                HttpContext ctx = HttpContext.Current;
-                               if (ctx != null && ctx.IsCustomErrorEnabled)
-                                       return GetCustomErrorDefaultMessage ();
+                               if (ctx != null && ctx.IsCustomErrorEnabled) {
+                                       if (http_code != 404 && http_code != 403)
+                                               return GetCustomErrorDefaultMessage ();
+                                       else
+                                               return GetDefaultErrorMessage (false);
+                               }
                                
                                if (!(this.InnerException is HtmlizedException))
-                                       return GetDefaultErrorMessage ();
+                                       return GetDefaultErrorMessage (true);
                                
                                return GetHtmlizedErrorMessage ();
                        } catch (Exception ex) {
@@ -211,33 +215,35 @@ table.sampleCode {{width: 100%; background-color: #ffffcc; }}
                
                void WriteFileBottom (StringBuilder builder, bool showTrace)
                {
-                       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 (!showTrace)
-                               return;
-                       
-                       string trace, message;
-                       bool haveTrace;
-                       Exception ex = this;
+                       if (showTrace) {
+                               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);
                        
-                       while (ex != null) {
-                               trace = ex.StackTrace;
-                               message = ex.Message;
-                               haveTrace = (trace != null && trace.Length > 0);
+                               string trace, message;
+                               bool haveTrace;
+                               Exception ex = this;
+
+                               builder.Append ("\r\n<!--");
+                               while (ex != null) {
+                                       trace = ex.StackTrace;
+                                       message = ex.Message;
+                                       haveTrace = (trace != null && trace.Length > 0);
                                
-                               if (!haveTrace && (message == null || message.Length == 0)) {
-                                       ex = ex.InnerException;
-                                       continue;
-                               }
+                                       if (!haveTrace && (message == null || message.Length == 0)) {
+                                               ex = ex.InnerException;
+                                               continue;
+                                       }
 
-                               builder.Append ("\r\n[" + ex.GetType () + "]: " + HtmlEncode (message) + "\r\n");
-                               if (haveTrace)
-                                       builder.Append (ex.StackTrace);
+                                       builder.Append ("\r\n[" + ex.GetType () + "]: " + HtmlEncode (message) + "\r\n");
+                                       if (haveTrace)
+                                               builder.Append (ex.StackTrace);
                                
-                               ex = ex.InnerException;
-                       }
+                                       ex = ex.InnerException;
+                               }
                        
-                       builder.Append ("\r\n-->");
+                               builder.Append ("\r\n-->");
+                       } else
+                               builder.Append ("</body></html>\r\n");
                }
 
                string GetCustomErrorDefaultMessage ()
@@ -292,7 +298,7 @@ table.sampleCode {{width: 100%; background-color: #ffffcc; }}
                        return builder.ToString ();
                }
                
-               string GetDefaultErrorMessage ()
+               string GetDefaultErrorMessage (bool showTrace)
                {
                        Exception ex, baseEx;
                        ex = baseEx = GetBaseException ();
@@ -314,15 +320,15 @@ table.sampleCode {{width: 100%; background-color: #ffffcc; }}
                        builder.Append ("</p>\r\n");
 
                        if (resource_name != null && resource_name.Length > 0)
-                               builder.AppendFormat ("<p><strong>Resource URL: </strong>{0}</p>\r\n", resource_name);
+                               builder.AppendFormat ("<p><strong>Requested URL: </strong>{0}</p>\r\n", resource_name);
                        
-                       if (baseEx != null && http_code != 404) {
+                       if (showTrace && baseEx != null && http_code != 404 && http_code != 403) {
                                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, true);
+                       WriteFileBottom (builder, showTrace);
                        
                        return builder.ToString ();
                }