If you develop ASP.NET websites, you are probably aware that instead of using the built in Visual Studio Web Server (Cassini) for debugging, you can use IIS.
If you have configured this for your project, Visual Studio creates a virtual directory in IIS and pressing F5 to debug won't start the built in server but will instead attach to the IIS website.
Using IIS over Cassini has several advantages
, however, it still doesn't allow you to edit the source while you browse the site and virtual directories can be a pain when the live site will be running from root.
I prefer to leave these project settings alone and instead add an entirely new site in IIS, pointing at the codebase. This gives you more control over how the development site can be accessed and you can configure each site to use different SSL certificates, filter on host header values etc.
This allows easy browsing of the latest version of the development site, and allows you to quickly make changes to the source code, recompile and refresh. Since you are doing all of this outside of the debugger you can edit source code while keeping an eye on how the changes are affecting the site.
The only problem with this is if you are in the middle of using the site and you find a bug that you need to trace using the debugger, which of course isn't running in the current context. You can overcome by using the 'Debug > Attach to Process' menu and then selecting w3wp.exe. This will attach to the IIS process to and Visual Studio will load the debug symbols for the sites you are running, thus allowing you to set breakpoints in the code which will be fired by any browser triggering that line of code (also useful when you are testing accross multiple browsers).
This is quite a few keystrokes to get the debugger up and running, but fortunately Visual Studio allows you to create macros and assign shortcuts to them. I found a tutorial on how to create a macro that will attach to IIS and how to set up the shortcut
I set up my shortcut key as CTRL+0 which is an easy sequence to remember. The macro that is listed on the above link did not work on my machine, because I am on a domain. I edited the script to tidy it up and to make it more robust, below:
Option Strict Off
Option Explicit Off
Public Module AttachToIIS
Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
Dim dbgeng(3) As EnvDTE80.Engine
dbgeng(0) = trans.Engines.Item("Managed")
dbgeng(1) = trans.Engines.Item("Native")
dbgeng(2) = trans.Engines.Item("T-SQL")
Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, Environment.MachineName).Item("w3wp.exe")
Catch ex As System.Exception
If you get the error 'Invalid Index' it generally means that IIS has not loaded the application since a recompile, so you need to refresh the page in your browser first to reload it.