Application_start not working

后端 未结 5 552
青春惊慌失措
青春惊慌失措 2021-01-14 00:32

I have written some code in the application_start() method in my global.asax file. It does not get called when I deploy my application on IIS

5条回答
  •  情深已故
    2021-01-14 00:47

    If you are running Server 2008R2 (or earlier) and/or IIS 7.5, you might want to look into the Application Initialization module. This can be downloaded here:

    www.iis.net/downloads/microsoft/application-initialization

    With IIS versions prior to 8.0, the application start is not called until the first web request arrives. I'm reading your question as you want your application start to be fired before the first web request, yes?

    Here is a fantastic guide to configuring this module (if it applies to you): https://blogs.msdn.microsoft.com/benjaminperkins/2014/01/07/configure-the-iis-application-initialization-module/

    The key takeaways is that you need to set your app pool to 'AlwaysRunning' instead of 'OnDemand'. You also need to set a preloadEnabled flag for your website. Once both of these are done, fire off an iisreset and you should see the results of your application start (look in the database since it's writing there).

    Other answers are relevant as well, in that this is tough to debug and you're missing all the niceties you're used to such as a httpcontext in app start.

    If you are running IIS 8.0 - you should still read the above link to configure preloading.

提交回复
热议问题