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

89 questions
4
votes
1 answer

azure webrole Global.Application_Start is never called

I created a simple ASP.NET project and then added cloud deployment descriptor using Visual Studio. Once I do that, Application_Start() method in global.asax file never gets called. In my project, I do lot of initialization such as loading web.config…
phebbar
  • 265
  • 1
  • 3
  • 12
3
votes
1 answer

StyleCop SP0100 error for Application_Start in Global.asax

Style cop will try to force you to take the underscore out of Application_Start in the Global.asax file in an mvc web application: SP0100: Method (general) name Application_Start doesn't conform the specified style: SampleName. But this name…
DevDave
  • 6,700
  • 12
  • 65
  • 99
3
votes
4 answers

Why does Application_Start run in Cassini but not in IIS7?

I have an ASP.NET 3.5 sp1 app that's in development in Cassini. The app includes a global.asax file that should run some code - it works fine in Cassini but in IIS the debugger never hits the function. Why doesn't that code run?
James Cadd
  • 12,136
  • 30
  • 85
  • 134
3
votes
3 answers

Stop execution of ASP.NET application

In my Application_Start() method, how can I stop the execution of the ASP.NET application when certain conditions are not met? Throwing an exception doesn't appear to work.
David Brown
  • 35,411
  • 11
  • 83
  • 132
3
votes
0 answers

Get base url from a scheduled task in application start

I have a TaskScheduler with the function EmailInactiveUsers that I start from Application_Start(). I need a link to the root of my application in my email that I send out. But how do I get the base url of my application without having access to an…
Niklas
  • 13,005
  • 23
  • 79
  • 119
3
votes
1 answer

Application_Start not firing in ASP.NET MVC app

I've got an ASP.NET MVC app where the Application_Start event appears to not be firing. The symptoms are that an NLog log statement in that handler does not generate a log entry, and none of my routes get populated (so all my requests for controller…
joelt
  • 2,672
  • 2
  • 24
  • 32
3
votes
1 answer

Application_Start does not respond to RegisterAllAreas()

I'm new on MVC Application, please help me. I have an Application on Visual Studio 2012 using Framework 4.0 on a Windows 7 pc and I'm debugging in IIS Express. Starting debugging, my application doesn't respond: after starting Application_Start in…
fda
  • 39
  • 3
2
votes
1 answer

Azure Application_End not hit and Application_Start hits multiple times (a few minutes in between)

In my Azure environment I have a webrole with on the instances multiple websites. The Application_Start() method in global.asax in a WCF-project is called multiple times (a few minutes in between), without the Application_End or Application_Error…
2
votes
1 answer

How to create a singleton class which runs when ASP.NET WEB FORMS starts (without dependency on the user login)

I have an ASP.NET web form application hosted on IIS. In the app, I have a code snippet that should make some work on the background from the moment the application starts. The problem is when I have created the singleton class and initialize it…
2
votes
2 answers

Application_Start Vs Session_Start

Actually I am new to ASP.NET and I came through these concepts. What is the difference between Application_Start Vs Session_Start? And also how to know how many users are currently active in our application? Is by using Application_Start or by…
2
votes
3 answers

What code whould be placed in the application_start and the session_start events in global.asax?

Can you give an example of what might be best suited to place in the Application_Start and Session_Start subroutines? I know when each subroutine is called. Application_Start when the first user first accesses the web application. Session_Start…
Para
  • 2,022
  • 5
  • 34
  • 73
2
votes
0 answers

IIS idle timeout and Application_Start

I have an MVC web app hosted in IIS.The Idle timeout in the application pool configuration option has the default value of 20 minutes.That means that the application pool will terminate after 20 minutes so that it can start up again on the next…
fdhsdrdark
  • 144
  • 1
  • 13
2
votes
0 answers

MVC 5 Application_Start() called multiple times

I am new to MVC 5 and beginner for Visual Studio. I am facing this weird problem. Every time i change some thing in Layout.cshtml or anywhere in controller or view and run it .The Application_Start() method is called multiple times and i lose all my…
Suman Palikhe
  • 357
  • 1
  • 4
  • 16
2
votes
2 answers

Intermittant exception in Application_Start - how do I un-start the application?

In our Application_Start event handler we're performing some actions that intermittently fail due to file locking issues. In this scenario we would like to return the application to an "un-started" state. By this I mean that the user will be shown…
Richard Ev
  • 52,939
  • 59
  • 191
  • 278
2
votes
0 answers

When - and why - does ASP.NET MVC 4 instantiate the global application class?

I've been trying to use LightInject in an ASP.NET MVC 4 app, and uncovered something that's got me scratching my head. My code looks like this: public class MvcApplication : System.Web.HttpApplication { private ServiceContainer container; …
Dylan Beattie
  • 53,688
  • 35
  • 128
  • 197