System.Web.HttpApplicationFactory.GetApplication C# (CSharp) Method

GetApplication() static private method

static private GetApplication ( HttpContext context ) : System.Web.HttpApplication
context HttpContext
return System.Web.HttpApplication
		internal static HttpApplication GetApplication (HttpContext context)
		{
			HttpApplicationFactory factory = theFactory;
			HttpApplication app = null;
			if (factory.app_start_needed){
				if (context == null)
					return null;

				factory.InitType (context);
				lock (factory) {
					if (factory.app_start_needed) {
						foreach (string dir in HttpApplication.BinDirs)
							WatchLocationForRestart (dir, "*.dll");
						// Restart if the App_* directories are created...
			                        WatchLocationForRestart (".", "App_Code");
			                        WatchLocationForRestart (".", "App_Browsers");
			                        WatchLocationForRestart (".", "App_GlobalResources");
			                        // ...or their contents is changed.
			                        WatchLocationForRestart ("App_Code", "*", true);
			                        WatchLocationForRestart ("App_Browsers", "*");
			                        WatchLocationForRestart ("App_GlobalResources", "*");
			                        app = factory.FireOnAppStart (context);
						factory.app_start_needed = false;
						return app;
					}
				}
			}

			app = (HttpApplication) Interlocked.Exchange (ref factory.next_free, null);
			if (app != null) {
				app.RequestCompleted = false;
				return app;
			}

			lock (factory.available) {
				if (factory.available.Count > 0) {
					app = (HttpApplication) factory.available.Pop ();
					app.RequestCompleted = false;
					return app;
				}
			}
			
			return (HttpApplication) Activator.CreateInstance (factory.app_type, true);
		}

Usage Example

Example #1
0
        static void Process(HttpWorkerRequest req)
        {
            bool error = false;

            if (firstRun)
            {
                firstRun = false;
                if (initialException != null)
                {
                    FinishWithException(req, HttpException.NewWithCode("Initial exception", initialException, WebEventCodes.RuntimeErrorRequestAbort));
                    error = true;
                }
                SetupOfflineWatch();
            }
            HttpContext context = new HttpContext(req);

            HttpContext.Current = context;
            if (AppIsOffline(context))
            {
                return;
            }

            //
            // Get application instance (create or reuse an instance of the correct class)
            //
            HttpApplication app = null;

            if (!error)
            {
                try {
                    app = HttpApplicationFactory.GetApplication(context);
                } catch (Exception e) {
                    FinishWithException(req, HttpException.NewWithCode(String.Empty, e, WebEventCodes.RuntimeErrorRequestAbort));
                    error = true;
                }
            }

            if (error)
            {
                context.Request.ReleaseResources();
                context.Response.ReleaseResources();
                HttpContext.Current = null;
            }
            else
            {
                context.ApplicationInstance = app;
                req.SetEndOfSendNotification(end_of_send_cb, context);

                //
                // Ask application to service the request
                //

                IHttpHandler ihh = app;
//				IAsyncResult appiar = ihah.BeginProcessRequest (context, new AsyncCallback (request_processed), context);
//				ihah.EndProcessRequest (appiar);
                ihh.ProcessRequest(context);

                HttpApplicationFactory.Recycle(app);
            }
        }
All Usage Examples Of System.Web.HttpApplicationFactory::GetApplication