Problem:

Lets say, you have deployed your web application on the client and the client reports you a bug. You try to reproduce that bug in the Development envirnment but you failed.

The production environment is different then your development environment. Now what ? You should debug the application but how ? There are 2 problems

  • The application is deployed on IIS
  • The application is hosted at the client PC.

Solution:

Lets dig down the problem and see what exacly we can do to solve this.

.Net by default gives us the following options for debugging.

  • Visual Studio Internal Debugger
  • Local IIS debugger
  • Remote Debugging

Note: First 2 are out of the scope of this article but they are pretty much the same.

Remote Debugging Tool in Visual Studio 2010:

The tool which is used for remote debugging of ASP.Net application is known as “Msvsmon.exe”. The remote debugging tool is a small windows based application that Visual studio 2010 uses. It has a simple user interface that make it very simple to setup and configure.

Where is Msvsmon.exe?

You can find the remote debugging tool at the following path

<YourInstalledPath>\Microsoft Visual Studio 10.0\Common7\IDE\Remote Debugger

Go to the above path and run the msvsmon.exe (Note: If you have a 32 bit machine then open the x86 folder else open the x64 folder to run the exe.)

After running the exe you will see a window like the following. (Run the exe at the remote PC)

 

Configuration of Authentication Mode:

Msvmon supports 2 types of authentication modes

  • No- Authentication
  • Windows Authentication

No Authentication mode is less secure and should be avoided. We will discuss the windows authentication mode.

Now, you have to give rights to the person who will be doing the debugging on the remote PC.

Go to Tools > Options and you will a window like below.

Press the Permission Button to the rights to the domain user for debugging.

Now, the remote debugger is ready to accept the new connection. Now, the basic configurations are done and we are moving towards the debugging part.

Connecting to Remote IIS and Starting Debugging:

Before connecting lets first initiate a worker process on the remote PC. To initiate a worker process you need to run the application, the IIS will do the rest. You will see the benefits of this soon.

Now, run the application on your PC and press Ctrl + Alt + P to open the process attaching window.

In the above picture, you see a Qualifier dropdown. From this drop down you have to select the Remote Server name. (Hint: Use the Browse button – It will make your life easier)

After selecting the Correct Remote Server name, the “Process Available” List will be updated. See the Image below.

 

Select the worker process from the list and press Attach. The name of the worker process is w3wp.exe. You might see multiple instances of w3wp.exe but you have to select the correct one.  (I have found no rule to select the right process at first go so you can use hit and trial :).)

After this, go to the Remote PC and you will see that the Remote Debugging tool will say that someone has connected. See the image below.

Now, set a break point in your code and enjoy the debugging. 🙂

Complete Scenerio/Summary/Notes:

  •  Two main terms Remote Pc and the Host Pc. (Remote PC is the one where we have IIS and the application — and Host PC is the one where we have the Code). For Example, Remote PC is the client PC and Host PC is your PC.
  • As we have to connect to the Client/Remote Pc for debugging we have to start the Debugging tool on the Remote Pc.
  • As we have the Code on our PC so will attach our Visual Studio with the Remote PC.
  • We cannot attach the Debugger if the build that is deployed is in Release Mode.
  • Only the applications that are build in Debug mode can benifit from the Remote Debugging.
  • If you attach the wrong Worker Process then you will see an Exclamation Mark (!) on the Break Point. Choose some other worker process.
  • I have noticed that you should not remove the PDF files in the Bin folder as they help Visual Studio while debugging
  • If you want to connec to the Locally deployed application on IIS. Then simple open the Attach process window and select the w3wp.exe and press attach. (You process should already be running)