HttpApplication.Application_Start not firing after upgrade to Web API 2

耗尽温柔 提交于 2019-12-08 15:40:48

问题


I upgraded an application to Web Api 2 and the Application_Start would not fire post upgrade running on IIS Express. I did follow the official upgrade path at http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2 and have triple checked my settings.

The application uses StructureMap MVC 4 to inject dependencies. So WebActivator's PreApplicationStartMethod gets fired and the dependency resolver gets set correctly. After that, no other execution can be traced. I have enabled Edit and Continue and yet break point at the start of Application_Start is not hit.

Here's all that I've tried: a. Disable PreApplicationStartMethod and run the app b. Change the compile settings of the Global.asax and the code behind c. Create another WebApi2 project with similar structure and set up minus the actual code and that works fine

I have cleaned and run the app; also have cleaned the Temp ASP.NET folder

Appreciate the help towards resolving this issue.


回答1:


Your debugger attaches after your application is started, therefor you won't hit any breakpoints in your application start method. A workaround is to cause your webserver to restart while you're attached to the process:

Simply edit your web.config (just add a space) and save it, this will make your http application restart.




回答2:


Put a Debugger.Break(); statement in your Application_Start, and then do an iisreset or recycle your app pool, then hit F5. A Just in time debugger window should appear if a breakpoint doesn't cut it.




回答3:


Make sure IIS Express is shut down, then F5 again to see if Application_Start is hit.




回答4:


I just ran into the same problem. The global.asax.cs method Application_Start() had no parameters. Once I added the standard ones Application_Start(object sender, EventArgs e) the method got hit.



来源:https://stackoverflow.com/questions/19692981/httpapplication-application-start-not-firing-after-upgrade-to-web-api-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!