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.

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

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.

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

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!