I'm trying to use elmah for my MVC application and I've followed the steps on the wiki: http://code.google.com/p/elmah/wiki/MVC , but even so when trying to access myapp/elmah.axd the page:
404 - File or directory not found.
Anyone could help me please?
OBS: My IIS Version is 7.5
If helps I'm posting the pertinent sections of my web.config:
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="fals开发者_Python百科e" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
...
</connectionStrings>
<elmah>
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" />
</elmah>
<system.web>
...
<httpHandlers>
<remove verb="*" path="*.asmx" />
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />
<add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
And on my Global.asax.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
...
You need to populate the system.webServer config section also, for IIS 7+. See this question.
Here's a nice way of using ELMAH in MVC here that doesn't use the axd
but a controller and a custom ElmahActionResult
.
Try adding this to your web.config file in the
<system.webServer>
<handlers>
<remove name="ErrorLog" />
<remove name="ErrorMail" />
<remove name="ErrorFilter" />
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</handlers>
</system.webServer>
To help others experiencing what @zanona ran up against way back in 2010 (see comments to @hunter's reply above), the following change fixed the very same "HTTP Error 500.19 - Internal Server Error" for me today. Notice the placement of the configuration tags in @hunter's reply is what caused @zanona's error. Those tags @hunter mentioned belong under the modules heading, not the handlers one!
<modules>
<remove name="ErrorLog" />
<remove name="ErrorMail" />
<remove name="ErrorFilter" />
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</modules>
The above fix eliminated for me the very same "Config Error - Missing required attribute 'path'" issue that @zanona first reported. That error came as a result of the way tags in the handlers group are expected to be structured, and his rearranged tags caused obviously didn't have the path attribute (because they didn't belong there, but rather belong under the modules tag!). Now here's what tags in the handlers section should look like:
<handlers>
<add name="elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</handlers>
Notice the path attribute is present there? Ah!
Thanks to @hunter and @zanona because they did set me on the path I needed to solve my issue.
(NOTE: I've tried to edit the original post from @hunter above to make the corrections but peer review is slow and I thought I'd keep this reply here to help anyone facing the same challenge in the meanwhile. When that edit is accepted, we could delete this post.)
精彩评论