2006-01-10 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 10 Jan 2006 22:01:51 +0000 (22:01 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 10 Jan 2006 22:01:51 +0000 (22:01 -0000)
* HttpResponse.cs: typo in comment.

* HttpApplicationFactory.cs:
* HttpApplication.cs: don't discard the application used for running the
Application_Start event to allow for Redirect/Transfer to be used. Fail
to get the request/response from the application object as MS does (it
can still be retrieved through HttpContext.Current.blah). Fixes
bug #77162.

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

mcs/class/System.Web/System.Web/ChangeLog
mcs/class/System.Web/System.Web/HttpApplication.cs
mcs/class/System.Web/System.Web/HttpApplicationFactory.cs
mcs/class/System.Web/System.Web/HttpResponse.cs

index bc01f6ec3a687aea6b4920cc97689df4f7d152fd..0927a065c0504e3753acc19b1b3cf5b7615e4e48 100644 (file)
@@ -1,3 +1,14 @@
+2006-01-10 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * HttpResponse.cs: typo in comment.
+
+       * HttpApplicationFactory.cs:
+       * HttpApplication.cs: don't discard the application used for running the
+       Application_Start event to allow for Redirect/Transfer to be used. Fail
+       to get the request/response from the application object as MS does (it
+       can still be retrieved through HttpContext.Current.blah). Fixes
+       bug #77162.
+
 2006-01-09  Vladimir Krasnov <vladimirk@mainsoft.com>
 
        * CapabilitiesLoader.cs: Merged TARGET_JVM parts in LoadFile
index a0b8c9b413a0e047c803039e7bb446ff02e5ae45..61db77d0dfb05bd73930153e568baab260db3a40 100644 (file)
@@ -224,6 +224,10 @@ namespace System.Web {
                        get {
                                if (context == null)
                                        throw new HttpException (Locale.GetText ("No context is available."));
+
+                               if (false == HttpApplicationFactory.ContextAvailable)
+                                       throw new HttpException (Locale.GetText ("Request is not available in this context."));
+
                                return context.Request;
                        }
                }
@@ -234,6 +238,10 @@ namespace System.Web {
                        get {
                                if (context == null)
                                        throw new HttpException (Locale.GetText ("No context is available."));
+
+                               if (false == HttpApplicationFactory.ContextAvailable)
+                                       throw new HttpException (Locale.GetText ("Response is not available in this context."));
+
                                return context.Response;
                        }
                }
@@ -538,6 +546,10 @@ namespace System.Web {
                        stop_processing = true;
                }
 
+               internal bool RequestCompleted {
+                       set { stop_processing = value; }
+               }
+
                public virtual void Dispose ()
                {
                        if (modcoll != null) {
@@ -800,6 +812,9 @@ namespace System.Web {
                //
                IEnumerator Pipeline ()
                {
+                       if (stop_processing)
+                               yield return true;
+
                        if (BeginRequest != null)
                                foreach (bool stop in RunHooks (BeginRequest))
                                        yield return stop;
@@ -999,7 +1014,6 @@ namespace System.Web {
                {
                        InitOnce (true);
                        PreStart ();
-                       stop_processing = false;
                        pipeline = Pipeline ();
                        Tick ();
                }
index 2cb805cc49010e9f20888257dac7f1c0babb37cd..3b4990a13f5751cdeae4dfd17624b09cc288fc0e 100644 (file)
@@ -170,13 +170,14 @@ namespace System.Web {
                        return true;
                }
 
-               void FireOnAppStart (HttpContext context)
+               HttpApplication FireOnAppStart (HttpContext context)
                {
                        HttpApplication app = (HttpApplication) Activator.CreateInstance (app_type, true);
+                       context.ApplicationInstance = app;
                        app.SetContext (context);
                        object [] args = new object [] {app, EventArgs.Empty};
                        FireEvent ("Application_Start", app, args);
-                       Recycle (app);
+                       return app;
                }
 
                void FireOnAppEnd ()
@@ -399,6 +400,7 @@ namespace System.Web {
                internal static HttpApplication GetApplication (HttpContext context)
                {
                        HttpApplicationFactory factory = theFactory;
+                       HttpApplication app = null;
                        if (factory.needs_init){
                                if (context == null)
                                        return null;
@@ -414,20 +416,22 @@ namespace System.Web {
                                                // We watch bin or bin/*.dll if the directory exists
                                                factory.bin_watcher = CreateWatcher (bin, new FileSystemEventHandler (factory.OnAppFileChanged));
 #endif
-                                               factory.FireOnAppStart (context);
+                                               app = factory.FireOnAppStart (context);
                                                factory.app_start_needed = false;
+                                               return app;
                                        }
                                }
                        }
 
                        lock (factory.available) {
-                               if (factory.available.Count > 0)
-                                       return (HttpApplication) factory.available.Pop ();
+                               if (factory.available.Count > 0) {
+                                       app = (HttpApplication) factory.available.Pop ();
+                                       app.RequestCompleted = false;
+                                       return app;
+                               }
                        }
                        
-                       HttpApplication app = (HttpApplication) Activator.CreateInstance (factory.app_type, true);
-
-                       return app;
+                       return (HttpApplication) Activator.CreateInstance (factory.app_type, true);
                }
 
                // The lock is in InvokeSessionEnd
@@ -464,6 +468,10 @@ namespace System.Web {
                                        app.Dispose ();
                        }
                }
+
+               internal static bool ContextAvailable {
+                       get { return theFactory != null && theFactory.app_start_needed && theFactory.needs_init; }
+               }
        }
 }
 
index 745cc88ddc4c0bf3708ffff8635a26f96ac242be..6e46d9983b5a16acca25471684b3a4cfd38e12dd 100644 (file)
@@ -544,7 +544,7 @@ namespace System.Web {
 #endif
                        } else {
                                // If this is called from an async event, signal the completion
-                               // but don't thow.
+                               // but don't throw.
                                context.ApplicationInstance.CompleteRequest ();
                        }
                }