Questions tagged [application-end]

Application_End method called by ASP.NET once for the lifetime of the application domain, not for each HttpApplication instance. It been called once per lifetime of the application before the application is unloaded.

During asp.net application life cycle, the application raises events that you can handle and calls particular methods that you can override. To handle application events or methods, you can create a file named Global.asax in the root directory of your application.

If you create a Global.asax file, ASP.NET compiles it into a class derived from the HttpApplication class, and then uses the derived class to represent the application.

An instance of HttpApplication processes only one request at a time. This simplifies application event handling because you do not need to lock non-static members in the application class when you access them. This also allows you to store request-specific data in non-static members of the application class. For example, you can define a property in the Global.asax file and assign it a request-specific value.

ASP.NET automatically binds application events to handlers in the Global.asax file using the naming convention Application_event, such as Application_BeginRequest. This is similar to the way that ASP.NET page methods are automatically bound to events, such as the page's Page_Load event. For details, see ASP.NET Page Life Cycle Overview.

The Application_Start and Application_End methods are special methods that do not represent HttpApplication events. ASP.NET calls them once for the lifetime of the application domain, not for each HttpApplication instance.

The following table lists some of the events and methods that are used during the application life cycle. There are many more events than those listed, but they are not commonly used.

http://msdn.microsoft.com/en-us/library/ms178473.aspx

22 questions
45
votes
3 answers

Application_End global.asax

Can anybody tell me when Application_End is triggered in a lifecycle of an application? When all sessions are ended, will Application_End be triggered automatically? + Are there any other reasons why Application_End could be triggered?
Lieven Cardoen
  • 25,140
  • 52
  • 153
  • 244
9
votes
2 answers

Prevent IIS from unloading ASP.Net site

How do I prevent an ASP.Net site from being unloaded by IIS? I have what may be the dumbest website in the world - once per hour it wakes up and writes a timestamp to a log file. When the app starts, it says so with a timestamp in the log, and when…
Chris Moschini
  • 36,764
  • 19
  • 160
  • 190
7
votes
2 answers

How to get Application_End to run while debugging (or when stopping debugging)?

I want to handle application shutdown gracefully when stopping debugging or stopping the IIS Express web site, but I cannot seem to get Application_End to run.
6
votes
3 answers

IIS app pool recycling randomly every few seconds

I need to determine WHY the application pool is recycling. (its for no obvious reason) Is there any way to determine this inside of the application_end sub in the global.asax file? I have put some basic logging in there, so I know WHEN its shutting…
5
votes
2 answers

How to exit an ASP.NET application gracefully when stopping debugging in VS 2010?

I develop and debug an ASP.NET application with VS 2010. My ASP.NET application holds some connections to other applications on other machines. When I stop debugging, I want these connections to be released. If this doesn't happen, these other…
Rob Lu
  • 115
  • 12
5
votes
2 answers

When Application_End isn't called in asp.net WebService

I know that in the following cases Apllication_end will be called: edit the config file for an application that's running. change a dll in the bin directory. stop (or restart) IIS. Process Recycling turned on either in IIS6 App Pools, or using the…
Dor Cohen
  • 16,769
  • 23
  • 93
  • 161
4
votes
1 answer

How do I add a Application_End handler without using global.asax?

I'm writing an http module, and I want to add a method that is called when (and only when) the appdomain gets recycled. I don't want to add anything to global.asax, I want to do it programatically within the http module. However, there doesn't seem…
thecoop
  • 45,220
  • 19
  • 132
  • 189
4
votes
4 answers

Application_End() cannot access cache through HttpContext.Current.Cache[key]

I want to be able to maintain certain objects between application restarts. To do that, I want to write specific cached items out to disk in Global.asax Application_End() function and re-load them back on Application_Start(). I currently have a…
Carl J.
  • 343
  • 1
  • 3
  • 8
3
votes
1 answer

How to recognize that Session_OnEnd event raises because of Application end in MVC Application

In my ASP.NET MVC4 application I have Session_OnEnd and Application_End events. When application ends Session_OnEnd events called firstly, after that Application_End called. Is there a way to recognize in Session_OnEnd event that its happening for…
3
votes
0 answers

trying to identify source of bin dir change or directory rename app restart

I am logging Application_End events (IIS 7). My app occasionally generates this event with the following details in the shutdown message: "Change Notification for critical directories" and "bin dir change or directory rename". The recorded detail…
2
votes
2 answers

Server.MapPath inside Application_End handler in Global.asax

I want to save a file when my application ends. For that, I need to get the root folder of the application. The only way I know to do that is using Server.MapPath("~"), but this does not work, even through HttpContext.Current.Server because there is…
nir.arazi
  • 63
  • 10
2
votes
1 answer

Asp.net Application_End Timeout

In Asp.Net when an application pool stops, invokes the application_end event. In this event i execute some operations who must be completed before the application shutdown. These operations are synchronously but sometimes application stops without…
jed
  • 41
  • 5
1
vote
4 answers

Application_End() event is fired without any call in global.ascx

the Application_End() event in my application is getting fired without any call to the event by my code after i fire a button for update or delete process. this causes all the Sessions destroyed and redirects the user to Login page every time he…
Rupendra
  • 608
  • 2
  • 11
  • 42
1
vote
2 answers

The Application_end method in my ASP.NET MVC website is called many times weirdly almost at the same time

It is an ASP.NET MVC website. I add some log in the Application_end method. I know there are some circumstances when the Application_end will be called, such as application pool's recycle, web.config file's change, or bin file's change. But my…
Robin Sun
  • 1,352
  • 3
  • 20
  • 45
1
vote
1 answer

Why would IIS "start" an App that is still running?

We have an ASP.NET (3.5 SP1) application running on IIS7 / Windows 2008. We trap Application_Start and Application_End events in Global.asax. We also host WCF services in the app and trap the OnOpening and OnClosing events via a…
1
2