Elmah not working with asp.net site

China☆狼群 提交于 2019-11-26 21:17:22

Try registering the Modules and Handlers in the sections "httphandlers" and "httpmodules" in the <system.web> section:

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

    </httpHandlers>
    <httpModules>
        .......
        <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
        <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
        <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
       .......
    </httpModules>

I just had a similar problem with Elmah not working in an IIS7 deployment. I found that I needed to register the Elmah Modules and Handlers in system.web AND system.webServer:

<system.web>
...
  <httpHandlers>
    ...
    <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
    ...
  </httpHandlers>
  <httpModules>
    ...
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
    <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
    <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
    ...
  </httpModules>
  ...
</system.web>
<system.webServer>
  ...
  <modules runAllManagedModulesForAllRequests="true">
    ...
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
    <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
    <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
    ...
  </modules>
  <handlers>
    ...
    <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
    ...
  </handlers>
<system.webServer>

You may be need this one also

<elmah>
    <security allowRemoteAccess="1" />
</elmah> 

when you get

403 - Forbidden: Access is denied. You do not have permission to view this directory or page using the credentials that you supplied.

This line was missing when I installed using NuGet (VS 2013, IIS 8.0):

<system.webServer>
  <handlers>
    <add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
 </handlers>
</system.webServer>

Adding it solved the 404 error problem.

One way to get around it today is to use nuget.

Visual studio:menu->tools->library package manager->package manager console

install-package elmah

HTH

Prafulla

The nuget package does not add the following important lines to web.config resulting in 403 error.

<configuration>
  <elmah>  
    <security allowRemoteAccess="1" />
    <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/app_data/elmah" />
  </elmah>
</configuration>

Also you may want to restrict the access to error logs by

<add name="Elmah" verb="POST,GET,HEAD" path="/admin/elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />

if you are using Areas make sure that you have updated one of the appsetting key

Default

<add key="elmah.mvc.route" value="elmah" />

If you are an area as Admin

<add key="elmah.mvc.route" value="admin/elmah" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!