How to debug localhost (or running in IIS) Asp.net applications

Sometimes you may need to debug applications that you host in IIS. In case of a developer pc we can call it localhost applications. When we use Visual Studio, we can debug our application when we run the built-in web server of visual studio.

But when we want to test our application properly in IIS server (which we should always do to get the true outcome of the application) that type of straight forward debug can’t be done. But still we can debug our application and that is not so difficult as well. Here is the steps,

Step 1:

first deploy your application in IIS if it is not already deployed. In my case i created a virtual directory for my application in the usual way. lets say it can be run using the url http://localhost/test . now lets run the site using browser. It is important to run the localhost site using the browser (and keep the browser open  in some case) because otherwise we may not see the asp.net worker process in the process list.

Step 2:

Now run visual studio and open the project, put debug points where needed.

Step 3:

Now we have to attach the debugger with the asp.net worker process to do the debug.

Go to Debug > Attach to process…

Next choose the aspnet_wp.exe (in case of windows xp it is aspnet_wp.exe and in case of windows server 2003 it is w3wp.exe) and click Attach.

Step 4

Now browse the site using any the browser and debugger will fire wherever a debug point is placed.

Happy debugging !!!

 

Special Notes:

If you open the application in multiple browser or multiple times, it may happen that there will be several instance of the asp.net worker process, that is multiple aspnet_wp.exe/w3wp.exe in the process list. you need to pick the one that you are using for debug. finding which one is the correct one can be done by trial and error or there are some blogs in the net about several ways on how to do so. but as long as multiple process is not being handled, there is nothing to headache. if you need to find out easily which one is the correct process in case of multiple process, use google to find the solution best suite you.

Technorati Tags: ,,
Published 06-26-2009 4:14 PM by Jalal
Filed under: ,

Comments

# re: How to debug localhost (or running in IIS) Asp.net applications

Sunday, June 28, 2009 1:26 PM by Md Nazmul Ahsan

wow.. I have done the same work with windows service. I am surprised that it also work with ASP.NET. It will help me lot. Thanks for share this.

By the way, I like your blog motto. It is really different.

# re: How to debug localhost (or running in IIS) Asp.net applications

Sunday, June 28, 2009 7:49 PM by Tanzim Saqib

Why wouldn't it be working with ASP.NET as well? Both of them run as Services. Helpful post for getting started with ASP.NET though.

One issue - If you open the application in multiple browser or multiple times, it may happen that there will be several instance of the asp.net worker process, that is multiple aspnet_wp.exe/w3wp.exe in the process list.

This is absolutely wrong.

Powered by Community Server (Non-Commercial Edition), by Telligent Systems