Configuring Elmah in a Visual Studio 2010 Web Application hosted in Cassini Web Server

Recently, I was helping a co-worker set up Elmah error logger for a web application hosted in Cassini, which is the default light-weight web server in Visual Studio. I generally don’t recommend running anything in Cassini and setup projects in IIS from the start. Chances are you’ll have to do it anyway when you hit one of the limitations of this web server.

The solution we were working on was in Visual Studio 2010, which works with IIS 7 out of the box. Our problem was that after configuring Elmah and attempting to access the error log page, we were getting the “Resource not found” error. The first thing was to make sure the Elmah’s handler and modules were configured correctly.

<system.webServer>  
  <modules runAllManagedModulesForAllRequests="true">
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
  </modules>
  <handlers>
    <add name="ErrorLog" verb="POST,GET,HEAD" path="errorlog.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
  </handlers>
</system.webServer>  

Well, the problem is that system.webServer configuration section is for IIS 7 only. Cassini simply doesn’t read it (at least not the version that ships with VS 2010), so you have to define all handlers and modules in the system.web section instead.

<system.web>  
  <httpHandlers>
    <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
  </httpHandlers>
  <httpModules>
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
  </httpModules>
</system.web>  

Considering that everything else is configured correctly, Elmah should now run in Cassini. Note, this configuration will fail as soon as you run your application in IIS 7, as it expects all modules and handlers to be defined in system.webServer only. So, make sure to take out system.web handlers and modules for Elmah out before deploying to IIS 7!