Having recently moved my primary development environment over to Windows Vista I've been presented with a small learning curve when developing my ASP.NET applications. It's been good, however, as I've been forced to delve into IIS 7.0 and explore some of its capabilities and learn some of its nuances. To be sure, I'm very much enjoying working with it…but there's a lot to learn and become acquainted with.
I have a web application that I'd been working on in an IIS 5.5 (Windows XP) environment successfully prior to the migration so I thought I'd set it up and take it for a test drive in the IIS environment. I was pleased that I had but a few changes to make to make it operational. Getting it run from Visual Studio 2005 was a different story however.
I found that anytime I attempted to run my website by pressing F5 within Visual Studio I was presented with a dialog explaining that it was "Unable to start debugging on the web server. An authentication error occurred while communicating with the web server. Please see Help for assistance." I could, however, attach to the running process (w3wp.exe) and debug that way. In my case, while that would have worked most of the time, it didn't provide me access to some of the methods that I'd want to debug (like BeginRequest) and is a bit more cumbersome. Well, this was a bit disconcerting, but after a few minutes of tinkering in IIS to attempt to resolve it I resorted to running a quick Google search. It turns out I wasn't alone on this issue, not by a long shot. The first blog post I found was by Rajiv Popat and it was quite helpful, but not quite what I was looking for. In his post he recommends using the Classic Mode rather than the new Integrated Mode. NOTE: The Classic Mode that is provided with IIS 7.0 provides a runtime environment that mimics IIS 6.0. I could have used that happily, but as I'm not generally satisfied with workarounds or just settling for the first solution, er, band-aid that I find, I wanted to dig deeper and get my application working in the newer environment.
This is when I found a great blog post by Mike Volodarsky (a Program Manager on the IIS team). In his post he mentioned the key characteristic as to why I couldn't debug my site via F5: I had a global.asax file (though I deleted it – it wasn't necessary in my app) and a custom HttpModule that attaches to the HttpApplication.BeginRequest method. Apparently "there is a bug in ASP.NET Integrated mode that prevents authentication from taking place correctly for the debug auto-attach feature". Well, removing the custom HttpModule was not an option because it does some pretty slick URL rewriting for the site and is critical for its operation. That, combined with the fact that Classic Mode didn't really give me the warm fuzzies, led me to adopt his Debugging Assistant (64-bit Version). Man, what a life saver! This worked – though it didn't work at first for me when I tried it yesterday, but I hunkered down and resolved to figure out why tonight.
When running in IIS 7.0's Integrated Mode, the web server will not rely on settings within your section of the web.config file as it does in Classic Mode. Rather it relies on the new section. As per the instructions on Mike's site, I added the special debug module and handler to the appropriate sections in the web.config file, but I continued to receive the "An authentication error occurred communicating with the web server" error. It turns out that I was clearing the modules and not adding back in a module that is required for debugging: WindowsAuthenticationModule. Hey, I'm still learning IIS 7.0 here J This is approximately how my web.config appears:
<system.webServer>
<modules>
<clear />
<add name="debugassistant" />
<add name="WindowsAuthenticationModule" />
</modules>
<handlers>
<add name="DebugHandler" path="DebugAttach.aspx" verb="DEBUG" type="System.Web.HttpDebugHandler" />
</handlers>
</system.webServer>
It turns out the fix was quite easy once I knew what I was doing.