Debugging ASP in Visual Studio 2005

I recently had to go back in time, and debug some traditional/classic ASP.  The fact that the code was relatively nasty is pretty much irrelevant, having the capability to debug and edit in my familiar Visual Studio 2005 IDE made the job a little easier to bear! Here are the steps to enable ASP debugging in studio...

Firstly you need to Enable Server Side ASP script Debugging in IIS - this can be done at the web site level or at the virtual directly level.  For the web site go to the Home Directory Tab on properties page, and for the Virtual Directory go to the Virtual Directly tab on the properties page.  From this tab select the Configuration button under Application Settings.  On the Configuration screen select the Debugging tab and check the Enable server-side ASP script debugging.

The quick way to get to the point of debugging with all code in the IDE is to open the Web site in Visual Studio (File, Open, Web Site).

If you are using server side JavaScript then you can use the debugger statement in code to force debugging - you are offered the choice of debug tools...  Or you can attach to the running process using Debug Attach to Process.  On XP the ASP process runs under a process dllhost.exe under the IWAM user.  Clearly you need to ensure you attach to the correct process, fortunately the IDE gives a nice visual warning if you get the wrong one.


Either way you do it you will be shown a warning when attaching to the process


And once you attach you can step through the code as normal!

In the code I was looking at there was another interesting feature.  At some point during the difficult and painful life of this product the page Language had managed to get set to JScript.Encode (even though the code was no longer encrypted) which blocks debugging.