2010-04-21 Marek Habersack <mhabersack@novell.com>
authorMarek Habersack <grendel@twistedcode.net>
Tue, 20 Apr 2010 22:35:31 +0000 (22:35 -0000)
committerMarek Habersack <grendel@twistedcode.net>
Tue, 20 Apr 2010 22:35:31 +0000 (22:35 -0000)
     * HttpApplication.cs: update to fix for bug #572469 - ProcessError
     clears the error after handler return only if stop_processing is
     true. Also, stop_processing is never set before calling ProcessError

    Also added two more tests for the issue.

svn path=/trunk/mcs/; revision=155841

mcs/class/System.Web/System.Web/ChangeLog
mcs/class/System.Web/System.Web/HttpApplication.cs
mcs/class/System.Web/Test/standalone-tests/Unhandled_Exception_Global_Asax.cs
mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_03/default.aspx [new file with mode: 0644]
mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_03/global.asax [new file with mode: 0644]
mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_03/global.asax.cs [new file with mode: 0644]
mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_03/web.config [new file with mode: 0644]
mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_04/default.aspx [new file with mode: 0644]
mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_04/global.asax [new file with mode: 0644]
mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_04/global.asax.cs [new file with mode: 0644]
mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_04/web.config [new file with mode: 0644]

index d5de0aaabc555b721829234da20321b730974557..8cc0c03e41efd4144f33559d3ce02226b342cf67 100644 (file)
@@ -1,3 +1,9 @@
+2010-04-21  Marek Habersack  <mhabersack@novell.com>
+
+       * HttpApplication.cs: update to fix for bug #572469 - ProcessError
+       clears the error after handler return only if stop_processing is
+       true. Also, stop_processing is never set before calling ProcessError
+
 2010-04-02  Marek Habersack  <mhabersack@novell.com>
 
        * HttpException.cs: handle situations when current exception is an
index c87d4b4f329c7da0f3fd756ab0b9d9ff01077e00..4b55fdaeb5512901a3b9f641faeeea738ebbc7ab 100644 (file)
@@ -870,7 +870,8 @@ namespace System.Web
                                if (eh != null){
                                        try {
                                                eh (this, EventArgs.Empty);
-                                               context.ClearError ();
+                                               if (stop_processing)
+                                                       context.ClearError ();
                                        } catch (ThreadAbortException taex){
                                                context.ClearError ();
                                                if (FlagEnd.Value == taex.ExceptionState || HttpRuntime.DomainUnloading)
@@ -931,7 +932,6 @@ namespace System.Web
                        } catch (ThreadAbortException taex) {
                                object obj = taex.ExceptionState;
                                Thread.ResetAbort ();
-                               stop_processing = true;
                                if (obj is StepTimeout)
                                        ProcessError (new HttpException ("The request timed out."));
                                else {
@@ -939,11 +939,12 @@ namespace System.Web
                                        if (FlagEnd.Value != obj && !HttpRuntime.DomainUnloading)
                                                context.AddError (taex);
                                }
-
+                               
+                               stop_processing = true;
                                PipelineDone ();
                        } catch (Exception e) {
-                               stop_processing = true;
                                ProcessError (e);
+                               stop_processing = true;
                                PipelineDone ();
                        }
                }
index 6945e9bebc251ea16a50b684c8e77789d1a89129..bcb569cc2819ea19321be972ca1f271670e3533b 100644 (file)
@@ -40,7 +40,7 @@ using NUnit.Framework;
 
 namespace StandAloneTests.Unhandled_Exception_Global_Asax
 {
-       [TestCase ("Unhandled_Exception_Global_Asax 01", "Unhandled exception handled in Global.asax, test 01")]
+       [TestCase ("Unhandled_Exception_Global_Asax 01", "Unhandled exception not handled in Global.asax, test 01")]
        public sealed class Unhandled_Exception_Global_Asax_01 : ITestCase
        {
                public string PhysicalPath {
@@ -65,9 +65,11 @@ namespace StandAloneTests.Unhandled_Exception_Global_Asax
 
                void Default_Aspx (string result, TestRunItem runItem)
                {
-                       string originalHtml = @"<strong>Application error handled</strong>";
+                       string originalHtml1 = @"[System.Web.HttpUnhandledException]: Exception of type 'System.Web.HttpUnhandledException' was thrown.";
+                       string originalHtml2 = @"[System.InvalidOperationException]: test";
                        
-                       Helpers.ExtractAndCompareCodeFromHtml (result, originalHtml, "#A1");
+                       Assert.IsTrue (result.IndexOf (originalHtml1) != -1, "#A1");
+                       Assert.IsTrue (result.IndexOf (originalHtml2) != -1, "#A2");
                }
        }
 
@@ -101,5 +103,67 @@ namespace StandAloneTests.Unhandled_Exception_Global_Asax
                        Assert.IsTrue (result.IndexOf (originalHtml) != -1, "#A1");
                }
        }
+
+       [TestCase ("Unhandled_Exception_Global_Asax 03", "Unhandled exception handled in Global.asax, test 03")]
+       public sealed class Unhandled_Exception_Global_Asax_03 : ITestCase
+       {
+               public string PhysicalPath {
+                       get {
+                               return Path.Combine (
+                                       Consts.BasePhysicalDir,
+                                       Path.Combine ("Unhandled_Exception_Global_Asax", "test_03")
+                               );
+                       }
+               }
+               
+               public string VirtualPath  {
+                       get { return "/"; }
+               }
+
+               public bool SetUp (List <TestRunItem> runItems)
+               {
+                       runItems.Add (new TestRunItem ("/default.aspx", Default_Aspx));
+                       
+                       return true;
+               }
+
+               void Default_Aspx (string result, TestRunItem runItem)
+               {
+                       string originalHtml = @"<strong>Application error handled</strong>";
+                       
+                       Helpers.ExtractAndCompareCodeFromHtml (result, originalHtml, "#A1");
+               }
+       }
+
+       [TestCase ("Unhandled_Exception_Global_Asax 04", "Unhandled exception handled in Global.asax, test 04")]
+       public sealed class Unhandled_Exception_Global_Asax_04 : ITestCase
+       {
+               public string PhysicalPath {
+                       get {
+                               return Path.Combine (
+                                       Consts.BasePhysicalDir,
+                                       Path.Combine ("Unhandled_Exception_Global_Asax", "test_04")
+                               );
+                       }
+               }
+               
+               public string VirtualPath  {
+                       get { return "/"; }
+               }
+
+               public bool SetUp (List <TestRunItem> runItems)
+               {
+                       runItems.Add (new TestRunItem ("/default.aspx", Default_Aspx));
+                       
+                       return true;
+               }
+
+               void Default_Aspx (string result, TestRunItem runItem)
+               {
+                       string originalHtml = @"<h2>Object moved to <a href=""http://google.com/"">here</a></h2>";
+                       
+                       Assert.IsTrue (result.IndexOf (originalHtml) != -1, "#A1");
+               }
+       }
 }
 
diff --git a/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_03/default.aspx b/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_03/default.aspx
new file mode 100644 (file)
index 0000000..5f7522e
--- /dev/null
@@ -0,0 +1,17 @@
+<%@ Page Language="C#" %>
+<script runat="server">
+       void Page_Load (object sender, EventArgs e)
+       {
+               throw new InvalidOperationException ("test");
+       }
+</script>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head runat="server">
+       <title>Default</title>
+</head>
+<body>
+       <form id="form1" runat="server">
+       </form>
+</body>
+</html>
\ No newline at end of file
diff --git a/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_03/global.asax b/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_03/global.asax
new file mode 100644 (file)
index 0000000..4bc28a6
--- /dev/null
@@ -0,0 +1 @@
+<%@ Application CodeFile="global.asax.cs" Inherits="TestWebApp.Global" %>
diff --git a/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_03/global.asax.cs b/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_03/global.asax.cs
new file mode 100644 (file)
index 0000000..01a6f3c
--- /dev/null
@@ -0,0 +1,23 @@
+using System;
+using System.Collections;
+using System.ComponentModel;
+using System.Web;
+using System.Web.SessionState;
+
+namespace TestWebApp
+{
+       public partial class Global : System.Web.HttpApplication
+       {
+               protected virtual void Application_Error (Object sender, EventArgs e)
+               {
+                       HttpResponse response = Response;
+
+                       if (response != null) {
+                               string begin = (string)AppDomain.CurrentDomain.GetData ("BEGIN_CODE_MARKER");
+                               string end = (string)AppDomain.CurrentDomain.GetData ("END_CODE_MARKER");
+                               response.Write (begin + "<strong>Application error handled</strong>" + end);
+                       }
+                       Server.ClearError ();
+               }
+       }
+}
diff --git a/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_03/web.config b/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_03/web.config
new file mode 100644 (file)
index 0000000..27ba12c
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!--
+Web.config file for TestWebApp.
+
+The settings that can be used in this file are documented at 
+http://www.mono-project.com/Config_system.web and 
+http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
+-->
+<configuration>
+  <system.web>
+    <compilation defaultLanguage="C#" debug="true">
+      <assemblies>
+      </assemblies>
+    </compilation>
+    <customErrors mode="RemoteOnly">
+    </customErrors>
+    <authentication mode="None">
+    </authentication>
+    <authorization>
+      <allow users="*" />
+    </authorization>
+    <httpHandlers>
+    </httpHandlers>
+    <trace enabled="false" localOnly="true" pageOutput="false" requestLimit="10" traceMode="SortByTime" />
+    <sessionState mode="InProc" cookieless="false" timeout="20" />
+    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
+    <pages>
+    </pages>
+  </system.web>
+</configuration>
\ No newline at end of file
diff --git a/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_04/default.aspx b/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_04/default.aspx
new file mode 100644 (file)
index 0000000..5f7522e
--- /dev/null
@@ -0,0 +1,17 @@
+<%@ Page Language="C#" %>
+<script runat="server">
+       void Page_Load (object sender, EventArgs e)
+       {
+               throw new InvalidOperationException ("test");
+       }
+</script>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head runat="server">
+       <title>Default</title>
+</head>
+<body>
+       <form id="form1" runat="server">
+       </form>
+</body>
+</html>
\ No newline at end of file
diff --git a/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_04/global.asax b/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_04/global.asax
new file mode 100644 (file)
index 0000000..4bc28a6
--- /dev/null
@@ -0,0 +1 @@
+<%@ Application CodeFile="global.asax.cs" Inherits="TestWebApp.Global" %>
diff --git a/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_04/global.asax.cs b/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_04/global.asax.cs
new file mode 100644 (file)
index 0000000..ff8b54d
--- /dev/null
@@ -0,0 +1,16 @@
+using System;
+using System.Collections;
+using System.ComponentModel;
+using System.Web;
+using System.Web.SessionState;
+
+namespace TestWebApp
+{
+       public partial class Global : System.Web.HttpApplication
+       {
+               protected virtual void Application_Error (Object sender, EventArgs e)
+               {
+                       Response.Redirect ("http://google.com/");
+               }
+       }
+}
diff --git a/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_04/web.config b/mcs/class/System.Web/Test/standalone/Unhandled_Exception_Global_Asax/test_04/web.config
new file mode 100644 (file)
index 0000000..27ba12c
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!--
+Web.config file for TestWebApp.
+
+The settings that can be used in this file are documented at 
+http://www.mono-project.com/Config_system.web and 
+http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
+-->
+<configuration>
+  <system.web>
+    <compilation defaultLanguage="C#" debug="true">
+      <assemblies>
+      </assemblies>
+    </compilation>
+    <customErrors mode="RemoteOnly">
+    </customErrors>
+    <authentication mode="None">
+    </authentication>
+    <authorization>
+      <allow users="*" />
+    </authorization>
+    <httpHandlers>
+    </httpHandlers>
+    <trace enabled="false" localOnly="true" pageOutput="false" requestLimit="10" traceMode="SortByTime" />
+    <sessionState mode="InProc" cookieless="false" timeout="20" />
+    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
+    <pages>
+    </pages>
+  </system.web>
+</configuration>
\ No newline at end of file