If you have written an Internet Server extension DLL, you might be interested in getting it running under the debugger so you can trace its execution, set breakpoints, or monitor variable values after the extension is called. Getting the Microsoft Internet Information Server (IIS) up and running with your DLL in the debugger is a little tricky. You will need to first find a quiet server where you can debug your DLL in a controlled setting. Once you’ve found such a resource, you can start debugging your DLL.
Because of differences between version 3.0 and 4.0 of IIS, it is important to know which version you will be using to debug your DLL.
Follow these steps to debug an Internet Server extension DLL using IIS 3.0:
-e W3Svc
Debugging Tips
The IIS can be run as an interactive application, making debugging much easier. To do this you need to make a few changes to your system. For the user account that you are going to run the server under, you need to add a few privileges.
To add privileges, run User Manager. (If you're using Windows NT 3.51, run MUSRMGR.EXE. If you're using Windows NT 4.0, run USRMGR.EXE.) Click User Rights from the Policies menu. Select the Show Advanced User Rights check box. Then select Act as part of the operating system from the drop-down list on the right, and add the user account.
Repeat this process with Generate Security Audits (also in the drop-down list on the right). Make sure that all Internet Services (WWW, ftp, and gopher) are stopped and INETINFO.EXE is not running (use TLIST to check). Log off and log back on. You can then load the IIS with the command line:
INetInfo.Exe -e W3Svc
To load IIS under a debugger (for example, under WinDbg), use the following command line:
WinDbg INetInfo.Exe -e W3Svc
You are ready to go. In Visual C++, point to Debug on the Build menu and then click Go. This action starts the WWW publishing service, and the debugger will be aware of symbols in your DLL. You can ignore the warning that the file doesn’t have debugging information.
When you close Visual C++, save the workspace for INETINFO.EXE. That way, you can avoid reentering the settings for the debugging session. Just open the INETINFO.MDS workspace file when you are ready to start the debugger again.
Cached DLLs
You can adjust the registry setting at HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/W3SVC/Parameters/CacheExtensions to have the server reinitialize DLLs each time they are used. If this setting is 1, the server will keep DLLs loaded in memory as long as possible. This is the default setting for the server, since it helps the server achieve peak performance, and should only be changed if you are using the server for debugging. If you make the setting 0, the server will always reload extension DLLs each time they are used.
Forcing the server to reload your DLL is helpful when your DLL might be crashing or upsetting any per-instance data that it maintains. By forcing the server to reinitialize the DLL, you can get your DLL back into a predictable state with little effort. Be sure to test your DLL using the normal CacheExtensions setting, however, to make sure code in your DLL isn’t completely dependent on that initial state.
There are several ways to establish an environment for debugging your server components and Internet Server extension DLLs when using IIS 4.0 or later. If you are using a debugger capable of attaching to a Windows NT process, you can use this functionality to debug your component or extension. For example, if you are debugging with Visual C++, take the following steps:
If the debugger you are using cannot attach to a Windows NT process, take the following steps to establish an appropriate debugging environment:
Debugger = <DebuggerExeName> where DebuggerExeName is the full path to the debugger you are using.
When the World Wide Web Publishing Service is started, your debugger will also be launched. You can now set appropriate breakpoints in your Internet Server extension DLL.
You won't be able to set breakpoints in a component's source code until the component has been loaded into memory. To do this, start Internet Explorer and view the .ASP page containing the object. As soon as the page is loaded, you should be able to set breakpoints in your component. Click Refresh to view the page again, and trigger the breakpoints you selected. If the component cannot be loaded even once (for instance, if the fault occurs in component startup code), you need to load the component DLL prior to starting the debugging session. (See step 11 below.)
In some cases, you may not be able to use either of the two procedures outlined above. If you have difficulty using either of these strategies, there is a third approach, which has been described in previous releases of IIS. This third approach requires the establishing of Windows NT security privileges as well as making changes to the registry. It will also disable your ability to run IIS as a service. This approach should only be used if the previous two strategies have failed.
{61738644-F196-11D0-9953-00C04FD919C1} // IIS WAMREG admin Service
{9F0BD3A0-EC01-11D0-A6A0-00A0C922E752} // IIS Admin Crypto Extension
{A9E69610-B80D-11D0-B9B9-00A0C922E750} // IISADMIN Service
The LocalService keyword may be found in additional subkeys of AppID.
C:\WINNT\System32\Inetsrv\Inetinfo.exe
-e w3svc
Note After you have completed the debugging session, you must reverse steps 5 through 1 to restore the previous settings and allow IIS to run as a service.