Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Ensuring Application_Start Event Fires with the Next Request

Use a try-catch block and call the HttpRuntime's UnloadAppDomain method in the catch block. to ensure that the Application_Start event fires with the next request.


advertisement

ASP.NET websites need some static data to be initialized, so that subsequent requests can utilize the loaded data and load much faster. It is a common practice to write such code in the Application_Start Event in Global.asax.cs file.

protected override void Application_Start(object sender, EventArgs e)

However, the Application_Start event could fail for a numerous reasons. One of them could be the non-availability of a dependent resource, or if you have lined up a set of synchronous steps to build some cache data and one of them failed. To overcome this limitation, use a try-catch block and call the HttpRuntime's UnloadAppDomain method in the catch block. This will ensure that the Application_Start event fires with the next request.

catch (Exception ex)
{
               HttpRuntime.UnloadAppDomain();
}

 

Visit the DevX Tip Bank

 





   
Srinath M. S. says: "I would love to leave a footprint in this flat world."
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date