Tuesday, September 20, 2011

Finding the right web process to debug

I've always found it a bit annoying when I am using "Attach to process" to debug my code and see something like this:


Which w3wp.exe should I attach to? Ah, why not attach to all of them, even though you know it's not necessary.

Recently a wise man showed me a trick to find out which web process I should attach to just by adding a command as an external tool.

In Visual Studio, just go to Tools -> External Tools and then press "Add".



















For the 'Title' you can choose what ever you want to call your External Tool, I chose to call it "Find web process".
For the 'Command', just paste this: %windir%\system32\inetsrv\appcmd.exe and for the 'Arguments' you should use "list wp". Make sure you check "Use output window" and then just click "OK".

Now you can use your newly created command from the menu bar under "Tools" and the result will be shown in the output window. To make it even easier you can add a keyboard shortcut to it too, more about that here.

The appcmd application is part of IIS7. It's a fully featured command line interface to IIS so everything (probably) you can do through the IIS Manager UI you can do through appcmd. You can find more information about appcmd here.