Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 Session_Start event also fires twice, with the same Session ID value.

e.g.

[Header]
2010-09-10 14:52:36.331 INFO  Web.Global.Application_Start          START
2010-09-10 14:52:37.409 INFO  Web.Global.Session_Start              Session.SessionID=xxqjvun2ce2yqsumq1hfoj45
[Header]
2010-09-10 14:53:10.028 INFO  Web.Global.Application_Start          START
2010-09-10 14:53:10.325 INFO  Web.Global.Session_Start              Session.SessionID=xxqjvun2ce2yqsumq1hfoj45

I am running this on my local machine, under IIS 5.1. The project also uses ASP.NET MVC and the aspx page URL being used is altered using routing, using the technique shown on Phil Haack's site.

Any suggestions about what could cause this?

like image 495
Richard Ev Avatar asked Sep 10 '10 13:09

Richard Ev


People also ask

Which event handler fires only once in the starting from Global asax file?

Application_End: Fired when the last instance of an HttpApplication class is destroyed. It is fired only once during an application's lifetime.

What is Application_Start?

Called when the first resource (such as a page) in an ASP.NET application is requested. The Application_Start method is called only one time during the life cycle of an application. You can use this method to perform startup tasks such as loading data into the cache and initializing static values.

What is application_ acquirerequeststate?

Application_AcquireRequestState. Occurs when ASP.NET acquires the current state (for example, session state) that is associated with the current request. Application_AuthenticateRequest. Occurs when a security module has established the identity of the user.

What is application_ EndRequest?

Application_EndRequest() : Occurs with each request the application receives, just after the page code is executed. Session_Start() : Occurs whenever a new user request is received and a session is started. Session_End() : Occurs when a session times out or is programmatically ended.


2 Answers

We eventually realised that this was down to our IIS configuration.

Some time ago a decision was made to rename the virtual directory used for this website. This was done by adding a whole new virtual directory configuration, leaving the previous one in place. Essentially we had two virtual directories pointing at the same ASP.NET app!

The migration to the new virtual directory was never completed, so parts of the website still referenced the old one. Hence two Application_Start events...

The fix was to change to setup to the old virtual directory in IIS to be A redirection to a URL with the URL set to /NewVirtualDirectory$S$Q

like image 191
Richard Ev Avatar answered Sep 17 '22 16:09

Richard Ev


After spending 4 days, I have finally found the problem out! If you change any file in Bin directory, IIS resets your application and Application pool. For me, it was because of log.txt file that my program used to write in Bin directory. I changed the log file path and the problem has been vanished!

like image 39
Amir Abolhasani Avatar answered Sep 18 '22 16:09

Amir Abolhasani