How to debug classic ASP pages in VS 2005: IIS 5.1

Some time ago I blogged about how to debug classic ASP applications in VS 2005 with IIS 6. A few people discovered difficulties with debugging on Windows XP with IIS 5.1. Most probable reason is that default IIS setting is not to load extensions into IIS process. Here is KB article on how to debug ISAPI extensions (ASP is just an IIS extension).

The important part is that it is necessary to attach to a process that loaded asp.dll. When IIS Application Protection is set to Low, host process is inetinfo.exe. When Application Protection is Medium (default) or High, process name is dllhost.exe. But here is catch: dllhost.exe is a generic host that is used to load and access any dynamic library out of process when isolation is desired. Isolation is useful since if dll crashes or leaks memory the main process that spawned the dllhost.exe is unaffected. If you look in a Task Manager, you may find that there are several instances of the dllhost.exe running. Which one do you attach to?

Go to SysInternals and download ListDlls utility. Then open command window and type

listdlls -d asp.dll

This should give you process name (dllhost.exe) and process ID. Use PID in the Attach To Process dialog and attach as script.

If listdlls does not show any processes using asp.dll, then classic ASP is not running yet. You may want to run you ASP page first in order to force IIS to load the ASP extension library. Complete steps:

1. Open classic ASP in VS 2005.
2. Set breakpoint.
3. View page in browser or run without debugging.
4. Run listdlls -d asp.dll from command line and figure out which dllhost.exe loaded asp.dll
5. Debug | Attach to Process
6. Locate the process by its ID and attach to it as Script.
7. Refresh page in the browser and observe breakpoint hit.