Is it possible to debug Global.asax?

2019-01-16 11:22发布

I can't debug global.asax file!

I have some codes in Application_Start() method but when I set a break point in the method, it is ignored!

Is this normal?

10条回答
▲ chillily
2楼-- · 2019-01-16 11:41

Check that your web application is in debug mode (<compilation debug="true"> in web.config).

If you're using developer's IIS started by VS, just restart it or rebuild application.

If you're on normal IIS you have two options:

  1. For web-site is configured to work with development folder (where you VS web project is deployed) you just have to restart application pool set for that web-site and start debugging before first request reaches server (you can always restart app pool during debug).
  2. For web-site that works on another folder or even on remote server you have to attach to the process. To do this you need remote debugger installed on remote machine or your own (depends on web-server location) and use Debug - Attach to process menu, enter computer name and then select a process to debug. It is usually a w3wp.exe working in managed mode type.
查看更多
劫难
3楼-- · 2019-01-16 11:42

A simple way to break in Application_Start() is to use the System.Diagnostics.Debugger class. You can force the application to break by inserting System.Diagnostics.Debugger.Break() where you would like the debugger to break.

void Application_Start(object sender, EventArgs e) 
{
     System.Diagnostics.Debugger.Break();

     // ...
}
查看更多
Root(大扎)
4楼-- · 2019-01-16 11:44

In case all of answers not working, try:

<compilation debug="true" ... />

in web.config. ;)

查看更多
神经病院院长
5楼-- · 2019-01-16 11:50

Maybe you should try:

  • stopping development server in taskbar
  • switching the configuration from release to debug
查看更多
登录 后发表回答