简体   繁体   中英

Global.asax Application_Start not firing when debugging, but fires in production

I'm using Application_start to set my routes in an asp.net webforms application. It was working fine, then I cloned the repo on a new machine and it stopped working. The event never fires, and the routes never get set. So I end up with a lot of 404 errors.

I even went as far as to throw an exception in the event to make sure it's not firing and the exception was never thrown.

However, it works when I publish the application.

I would suggest you try stopping IISExpress manually before launching the application from Visual Studio.

Or just Go to Web section of the properties of your web project and check 'Enable Edit and Continue' at the bottom.

When you choose Edit and Continue then we recycle the ASP.Net Web Server process on every debug run (it is needed for the Edit & Continue functionality to work)… This way although you will see very marginal degrade in your performance you will still be able to debug your Application_Start() methods…

This should help you understand why you are facing the issue:

The reason behind this is that we do not kill the ASP.Net Web Server process after your every debug run and hence Application_Start() is not fired every time. There is a good reason why we do so… Starting ASP.Net Web Server process is an expensive task and in most of the scenarios recycling this process after every debug would adversely impact your performance… If you do not want to debug your Application_Start() method then probably you do not need to have the process restart and save performance most of the time…

The details are in the article linked below:

https://blogs.msdn.microsoft.com/webdev/2007/12/13/workaround-debugging-global-aspx-cs-application_start-with-asp-net-web-server-within-visual-studio/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM