无法中断global.asax/Application_Start [英] Can't break in global.asax / Application_Start
问题描述
我在Application_Start()
的第一行有一个断点,但是Visual Studio不会在其上断点.
I got a break point on the first line of Application_Start()
, but Visual Studio wont break on it.
Visual Studio已将自己附加到IIS的工作过程中:
Visual Studio have attached itself to the IIS working process:
在机器'SRD00510'上自动附加处理过程[[2092] w3wp.exe".
Auto-attach to process '[2092] w3wp.exe' on machine 'SRD00510' succeeded.
我在家庭控制器中的断点确实起作用.
My breakpoint in the home controller do work.
更新
我尝试过:
-
iisreset
- 重新启动Visual Studio
- 已重新启动.
- 试图重新安装aspnet(
aspnet_regiis -i
)
iisreset
- restarted visual studio
- Rebooted.
- Tried to reinstall aspnet (
aspnet_regiis -i
)
推荐答案
在阅读您的问题时,我假设您正在使用IIS进行调试,而不是Visual Studio Development Server.
Reading your question, I assume you are using IIS for debugging, not Visual Studio Development Server.
在这种情况下,调试应用程序启动非常棘手,因为仅在启动或回收应用程序池时才调用一次.当Visual Studio附加到该进程时,Application_Start已经在运行.
In this case, debugging application start is tricky, because it is only called once when the application pool is started or recycled. When Visual Studio attaches to the process, Application_Start has already been running.
诀窍是使应用程序池循环使用而不会终止您所附加的进程.
The trick is to make the application pool recycle without killing the process you are attached to.
执行以下操作:
- 在Visual Studio(必须以管理员身份运行)中,在以下位置设置断点 global.asax.cs并照常开始调试(F5).该页面在 您的网络浏览器,但没有命中断点.
- 诀窍:使用文本编辑器从其所在位置打开web.config 由IIS服务,对其进行更改(例如,在某处输入空白行),然后 保存.与回收IIS中的应用程序池相比,这 让应用程序池回收(从而通过 下次访问该网站时,请在global.asax.cs中启动Application_Start. 被称为)而不会终止您所依附的过程.
- 在您的Web浏览器中,重新加载页面.断点现在应该被击中!
- In Visual Studio (must be run as Administrator) set your breakpoint in global.asax.cs and start debugging as usual (F5). The page opens in your web browser, but the breakpoint isn't hit.
- Now the trick: With a text editor, open web.config from where it is served by IIS, change it (e.g. enter a blank line somewhere) and save it. In contrast to recycling the application pool in IIS, this lets the application pool recycle (and thus running through Application_Start in global.asax.cs the next time the web site is called) without killing the process you are attached to.
- In your web browser, reload the page. The breakpoint should be hit now!
这对我有用(IIS 7.5,VS2015).
That works for me (IIS 7.5, VS2015).
这篇关于无法中断global.asax/Application_Start的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!