global.asax 断点未命中
我的 ASP.NET 应用程序中有一些 C# 代码,位于 Global.asax.cs 代码文件中。在 Application_Start
、Session_Start
和 Application_Begin Request
中,我设置了一些断点。然而,这些都没有被击中。我正在使用 VS8 在本地计算机上工作。
这是我尝试过的:
- 停止 ASP 开发服务器
- 删除所有 ASP.NET 临时文件
- 创建新的
Global.asax
- 关闭 VS 并打开备份
- Clean 和 Rebuild 项目
在尝试这些之后,断点将没有击中。
有什么想法可能是为什么吗?
I have some code in my ASP.NET app in C# that's in the Global.asax.cs
code file. In the Application_Start
, Session_Start
and Application_Begin Request
I have set some breakpoints. However none of these are ever hit. I'm working on my local machine with VS8.
Here's what I've tried:
- Stopped the ASP Dev Server
- Deleted all ASP.NET Temporary files
- Created new
Global.asax
- Closing VS and opening back up
- Clean and Rebuild project
Upon trying my after these, the breakpoints will not hit.
Any ideas why this might be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我遇到了同样的问题。我假设您使用本地 IIS 而不是 VS 开发服务器。如果是这种情况,您将无法在 Global.asax.cs 文件中调试/单步执行此代码,因为在附加调试器时,此代码已在 IIS 中执行。但是,如果您使用开发服务器,则可以访问此代码,因为调试器已附加。
因此,更改项目属性中的服务器以使用 Visual Studio 开发服务器。
可以通过在 Visual Studio 中右键单击您的项目来找到它 >
项目属性
>Web 选项卡
>使用 Visual Studio 开发服务器
。I've run into this same problem. I'm assuming you are using your local IIS instead of the VS Development Server. If this is the case, you won't be able to debug/Step through this code in the Global.asax.cs file because by the time the debugger has attached, this code has already executed in IIS. However, if you use the Dev server, you have the ability to get to this code as the debugger will already be attached.
So, Change the server in your project properties to use the Visual Studio Development Server.
This can be found by right clicking your project within Visual Studio >
Project Properties
>Web tab
>Use Visual Studio Development Server
.对我有帮助的是添加:
System.Diagnostics.Debugger.Break();
到该Application_Start()
方法。What helped me was to add:
System.Diagnostics.Debugger.Break();
to thatApplication_Start()
method.在我正在处理的一个项目中,在选项卡中选择了“启动外部程序”选项:
这导致断点未被命中。
将“开始操作”更改为“当前页面”为我解决了这个问题。
On a project I was working on, the "Start external program" option was selected in the tab:
This was causing the breakpoints to not be hit.
Changing "Start Action" to "Current Page" fixed this problem for me.
正如另一个答案中提到的,Global.asax 代码将在调试器有机会附加之前运行。要解决这个问题,您可以开始调试,然后进入 IIS 并停止/启动应用程序,然后调试器将重新启动。
As metioned in another answer, the Global.asax code will run before the debugger gets chance to attach. To get around that you can start debugging, then go into IIS and Stop/Start the Application which should then have the debugger pick up the restart.
如果不想使用Visual Studio Development Server而使用IIS,可以执行以下操作(在VS2015 Professional中测试)
1)应用程序池处于运行状态 - 确保使用的应用程序池正在运行通过从您的 Web 应用程序访问页面(它可能由于空闲超时而停止)。
2) 附加到进程 -
Ctrl-Alt-P
或调试 ->附加到进程
->查找与您的应用程序相对应的 w3wp 进程。使用 ReAttach 扩展(创建快捷方式)可以大大加快附加到进程的速度最近附加的进程。
3) 应用程序池回收 - 通过进入 IIS 并回收它,或者更快地进入 web.config,进行无效更改(在标记之外放置一些空白),确保应用程序池回收)并保存
4) 开始调试 - 从 Web 应用程序向任何页面执行请求以强制其初始化。您应该能够从
Global.asax
中的任何启动方法放置并命中断点If you do not want to use Visual Studio Development Server and use IIS, you can do the following (tested in VS2015 Professional)
1) Application pool in a running state - make sure that used Application Pool is running by accessing a page from your Web app (it may be stopped due to a Idle timeout).
2) Attach to process -
Ctrl-Alt-P
orDebug -> Attach to Process
-> lookup your w3wp process that corresponds to your application.Attach to process can be greatly sped up by using ReAttach extension which creates shortcuts to recently attached processes.
3) Application pool recycle - make sure that the application pool recycles by either entering IIS and recycling it or even faster, by entering web.config, making a no-effect change (put some blank outside of tags) and saving it
4) Start debugging - Perform a request to any page from your web application to force its initialization. You should be able to place and hit breakpoints from any of the startup methods in the
Global.asax
我遇到过两次这个问题。我遇到的第一个项目是,我转到“项目属性”->“构建”->“高级...”,然后从“调试信息”下拉列表中选择“完整”。
第二次,我的 global.asax 中的断点没有被击中,但如果我将鼠标悬停在断点上,它会发出此警告:“源代码与原始版本不同。”
我终于发现,在这种情况下,我制作了该项目的备份副本以保留代码并正在使用该副本。即使它位于不同的文件夹中,它仍然使用 dll 作为原始的虚拟目录: http://localhost:4952 /
所以我在“项目属性”->“Web”->“项目 URL”中更改了它。我刚刚将端口更改为 http://localhost:49523/ 并且它有效。
它提示我创建虚拟目录,我说是,从那以后就没有遇到任何断点问题。
I had this issue twice. The first project this happened to me, I went to Project Properties->Build->Advanced... and selected "full" from the Debug Info dropdown.
The second time, the breakpoints in my global.asax we're not being hit but it gave this warning if I hovered over the breakpoint: "The source code is different from the original version."
I finally figured out that in this case, I had made a backup copy of this project to preserve the code and was working with the copy. Even though it was in a different folder, it was still using the dll for the virtual directory of the original: http://localhost:4952/
So I changed that in Project Properties->Web->Project URL. I just changed the port to http://localhost:49523/ and it worked.
It prompted me to create the virtual directory, I said yes and haven't had any problems with breakpoints since.