How to configure ELMAH to work with Windows Azure? I get a 404 on Elmah.axd
Solution 1
Azure is based on Windows Server 2008 and IIS7. This means that you need to populate the system.webServer part of the web.config file.
The sample file included with elmah's source code contains the details that you need to put in.
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory" />
<remove name="ScriptHandlerFactoryAppServices" />
<remove name="ScriptResource" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</handlers>
</system.webServer>
There are 2 elmah lines in the above block of xml that you will need to include, and the section in general should contain most if not all of those elements anyway.
EDIT: No longer required as this is now on by default:
For Elmah to work you will also need to modify the following line in your ServiceDefinition.csdef file:
<WebRole name="WebRole" enableNativeCodeExecution="true">
Solution 2
Also secure the file so only allowed users can view the error logs!
<location path="admin/elmah.axd">
<system.web>
<authorization>
<allow roles="Administrator" />
<deny users="*" />
</authorization>
</system.web>
</location>
Solution 3
I think additionally (to what suggested by @mat1t here) you may need to set remote access to 1:
<elmah>
<security allowRemoteAccess="0" />
..............
..............
</elmah>
Rob Volk
I am a .NET web developer and the CTO of Live Smart Solutions (http://www.beyonddiet.com). I build web applications with good user experience in mind, incorporating AJAX using jQuery and standards-based HTML and CSS. I have over eight years' professional experience developing in C# and have MCPD-EA certification.
Updated on June 15, 2022Comments
-
Rob Volk almost 2 years
I have an ASP.NET MVC web role running on Windows Azure and have setup ELMAH properly in the web.config. I also have my global.asax ignore *.axd routes. Locally, I am able to load /elmah.axd, however when I deploy to Azure, I get a 404 on that page. Has anyone gotten ELMAH working on Azure?
-
KevinUK almost 15 yearsI had it working locally on my Vista PC but on the live server it was not working until I added the 2 Elmah lines you mention at the bottom of the web.config. I did not have to go into the ServiceDefinition file though. Once I made those changes I was getting a 403 error which is why you need to set allowRemoteAccess to 1
-
Bern over 11 yearsFurther to this I'm using the Oct 2012 Azure SDK and found I only needed the (1) <handler><add name="elmah" ... /> entry, and (2) the .csdef entry noted in the above answer. Also compared to a standard MVC web application where you can get to elmah via "/elmah" (depending on your elmah.mvc.route configuration) with an Azure MVC web role it will be "/elmah/elmah.axd". Good luck.
-
Bern over 11 yearsThere is a web.config <appSettings> option for this: <add key="elmah.mvc.allowedRoles" value="Administrator" /> that should take care of this.
-
Brian Ogden over 10 yearsenableNativeCodeExecution is set to true by default anyways: msdn.microsoft.com/en-us/library/windowsazure/gg557553.aspx
-
James over 10 years@BrianOgden: It didn't used to be back in the first version of Azure. I'll update the anser