问题描述
我有一个ASP.Net应用程序,在Global.asax中的Application_Start期间执行一些数据库初始化。我使用IIS Express调试应用程序。我发现如果我停止调试,清除数据库,然后重新启动,Application_Start代码不会被调用,我的数据库没有初始化正确,所以我的应用程序失败。这是因为IIS Express实例在调试停止后仍然运行。而不是重新启动它,Visual Studio似乎附加到现有的进程。
有没有办法改变这种行为,以便启动新的调试会话始终重新启动应用程序IIS Express中的进程(或在常规IIS中重置应用程序池)?
或者,是否有办法强制IIS Express在调试会话结束时关闭? / p>
我确实发现,如果在项目设置中的Web对话框中勾选启用编辑并继续,那么在调试结束时它具有停止IIS Express的副作用。但我不知道我是否想要介绍编辑和继续的副作用,只是为了停止IIS Express。当然有更好的方法?
不知道是否重要,但这是VS2012。
不幸的是,通过配置无法实现。我可能会提出你另一个伎俩,但是由你决定是否比你的更好:)
你可以创建一个更改时间戳的后期制作事件的web.config文件。我使用了上的touch.exe工具。您还需要将运行后构建事件设置为始终。因此,您的构建事件配置可能如下所示:
随着启动调试器,此选项将设置,web.config时间戳更新导致应用程序重新启动(应用程序appdomain重新加载)在第一个请求 - 但在这一点上,您已经附加到此过程,因此您的应用程序_
事件断点应该可以工作。
I have an ASP.Net application that performs some database initialization during Application_Start in Global.asax. I'm using IIS Express to debug the application.
I find that if I stop debugging, clear the database, and restart again, the Application_Start code does not get called and my database is not initialized properly, so my application fails. This is because the IIS Express instance is still running after debugging stops. Rather than restarting it, Visual Studio appears to be attaching to the existing process.
Is there a way to change this behavior such that starting a new debugging session always restarts the application process in IIS Express (or resets the application pool in regular IIS)?
Alternatively, is there a way to force IIS Express to shut down when the debugging session ends?
I did find that if I check "Enable Edit and Continue" from the Web dialog in the project settings, that it has the side effect of stopping IIS Express when debugging ends. But I'm not sure I want to introduce the side-effects of Edit and Continue just for the purposes of stopping IIS Express. Surely there's a better way?
Not sure if it matters, but this is VS2012.
Unfortunately it's not achievable through configuration. I may propose you another trick, but it's up to you to decide whether it's better than yours or not :)
You may create a post-build event which changes the timestamp of a web.config file. I used a touch.exe tool from http://www.stevemiller.net/apps/. You also need to set the "Run the post-build event" to Always. So your "Build Events" configuration may look as follows:
With this option set anytime you start the debugger, web.config timestamp is getting updated causing application restart (application appdomain reload) on the first request - but at this point you are already attached to this process so your Application_
event breakpoints should work.
这篇关于Visual Studio可以在新的调试会话中重新启动IIS Express吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!