简体   繁体   中英

How to Debug Initialize() in web application

I'm trying to create a method that is called when the application is initialized, except when creating a web application, you can only debug it by attaching it to the IIS process (w3wp.exe).

The problem is that this process is only created after initializing the application, which make it impossible to attach the Visual studio debugger to it before calling that method.

Anyone has a solution for this??

You can use the Cassini web server that is included with Visual Studio. In the Web settings for your project you should select User Visual Studio Development Server . This will allow you to debug your application by pressing F5 .

If you really need to debug inside IIS you can force a debugger break in your Initialize method by doing a call to Debugger.Break . If you have a debuger installed you will get the option to attach a debugger.

If you a have a very unwieldly application that is hard to debug (besides refactoring it into more managable and testable parts) you can instrument your code with logging. This will allow you to troubleshoot your application even in a production environment. .NET has built-in support for logging and there also exists several good open source frameworks that you can use.

Set your project to use IIS instead of ASP dev server and create a default web virtual directory that points to your UI dev directories. This is easily done from project properties within Visual Studio.

Build in debug form and then you can either browse your web from IIS or by typing the web directory for the project.

You'll need to register ASP with IIS:

In command window, navigate to " C:\\Windows\\microsoft.net\\framework\\v2.0.50727 " where C is your boot drive.

then run " ASPNET_REGIIS -i " this register ASP.NET with IIS

and then " ASPNET_REGIIS -ga ASPNET " this grants IIS access rights to ASP.NET

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM