Questions tagged [application-start]

Application_Start method called by ASP.NET once for the lifetime of the application domain, not for each HttpApplication instance. It's called when the first resource (such as a page) in an ASP.NET application is requested.

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

88 questions
125
votes
4 answers

How can I use Server.MapPath() from global.asax?

I need to use Server.MapPath() to combine some files path that I store in the web.config. However, since Server.MapPath() relies on the current HttpContext (I think), I am unable to do this. When trying to use the method, even though its…
John Bubriski
  • 18,881
  • 34
  • 115
  • 167
15
votes
1 answer

What happens if an unhandled exception is thrown in Application_Start?

... will the Application_Start method be ran again for the next request(s) or not? Does it depend on ASP.NET version, hosting server version and/or other context? I am trying to determine if it's a good thing to load critical assemblies there or…
Andrei Rînea
  • 18,961
  • 16
  • 112
  • 162
13
votes
4 answers

Multiple Application_Start events firing

I am debugging an ASP.NET 2.0 application that is suffering from slow loading of the initial page. Through adding logging, I've found that the Application_Start event fires twice on startup with a short delay between the two events. The…
Richard Ev
  • 48,781
  • 54
  • 181
  • 273
10
votes
2 answers

log4net Configuration for console app

can anyone suggest how to configure the log4net for an console app? Or at least how/where to catch the Application_Start event? (It seams that some calls are required at this moment) Thanks in advance!
mxg
  • 19,703
  • 12
  • 56
  • 77
10
votes
3 answers

What's the difference between the webrole onStart() event and Application_Start() global.asax event?

I'm just starting to get my feet wet learning the technical details of Azure, so apologies if this is a silly question. If I create a cloud service project in visual studio and add a webrole for an mvc application, within the mvc application I can…
Steviebob
  • 1,275
  • 1
  • 17
  • 32
9
votes
1 answer

Does Application_Start block all incoming requests

I have some code that initializes a static singleton class, which is needed by all requests. Therefore I thought I could add it to global.asax Application_Start. Can I be 100% sure that all requests will block while Application_Start is loading to…
Jeeji
  • 91
  • 1
7
votes
3 answers

Thread safety on Application Start

I have an ASP.NET application in which I am writing this code in Application_OnStart event: public virtual void OnStart(HttpApplication httpApplication) { MyClass.PopulateIndices(); } Now, I know that App_Onstart is fired only once, so my…
Rocky Singh
  • 13,980
  • 28
  • 91
  • 142
7
votes
1 answer

Application_Start ASP.NET

If get this from the Microsoft official documentation: 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…
ab_732
  • 3,093
  • 4
  • 33
  • 52
7
votes
1 answer

What is the best way to force an Application Start when an Application Pool is recycled?

I'm wondering if there is a way to automagically fire off an Application Start for a web site/application whenever the Application Pool for that site is recycled? Are there any canned solutions for this problem? I would really like to avoid having…
Joseph
  • 24,638
  • 8
  • 71
  • 121
5
votes
2 answers

HttpUtility.UrlEncode and Application_Start

As per http://ayende.com/blog/4599/hunt-the-bug, I've run into one of those scenarios whereby "Response is not available in this context". Greatly simplified, the following throws an exception in certain scenarios on Windows Server 2008/IIS7/ASP.NET…
Ted
  • 6,898
  • 8
  • 45
  • 73
5
votes
1 answer

Call to Application_Start after starting application pool in IIS

I would like to know how can I setup the IIS, or the application if needed, for the next requirement: - When the application pool starts in IIS it should call to Application_Start in Global.asax I was playing around with applicationHost.config…
fiso
  • 1,185
  • 1
  • 12
  • 20
5
votes
2 answers

How can you hook a SharePoint 2007 feature into the Application_Start of a site?

I was wondering if there is a good way to hook into the Application_Start of a SharePoint 2007 site when developing a feature? I know I can directly edit the Global.asax file in the site root, but is there a way to do this so that it gets deployed…
Bryant
  • 8,620
  • 31
  • 52
4
votes
1 answer

Elmah log error in Asp.Net MVC Application_Start

Possible Duplicate: elmah: exceptions without HttpContext? In Global.asax public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); …
4
votes
1 answer

Application_Start works fine on workstation, is not called when deployed

I have an application that works great on my development workstation but fails when the application is deployed to the live environment. It seems that Application_Start is not being called in the live environment.
vharron
  • 985
  • 10
  • 18
4
votes
1 answer

How can I register handlers for HttpApplication events outside of Init()

I'm creating a library that needs to run some code at various stages of the ASP.NET request lifecycle. It's easy to do this when writing a web application by overriding HttpApplication.Init() and registering various handlers there. However, I want…
ChaseMedallion
  • 19,262
  • 13
  • 76
  • 137
1
2 3 4 5 6