Елмаха не працює з сайтом asp.net


80

Я намагався використовувати elmah на своєму веб-сайті asp.net, але всякий раз, коли я намагаюся зайти на http: // localhost: port / elmah.axd, я отримую виняток, який не знайдено. Мій web.config наведено нижче.

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <sectionGroup name="elmah">
          <section name="security" requirePermission="false" 
                  type="Elmah.SecuritySectionHandler, Elmah"/>
          <section name="errorLog" requirePermission="false" 
                  type="Elmah.ErrorLogSectionHandler, Elmah" />
          <section name="errorMail" requirePermission="false" 
                  type="Elmah.ErrorMailSectionHandler, Elmah" />
          <section name="errorFilter" requirePermission="false" 
                  type="Elmah.ErrorFilterSectionHandler, Elmah"/>
        </sectionGroup>
      </configSections>
      <elmah>
        <security allowRemoteAccess="0" />
        <errorLog type="Elmah.SqlErrorLog, Elmah" 
                 connectionStringName="elmah-sql" />
        <errorMail
                from="my@account"
                to="myself"
                subject="ERROR From Elmah:"
                async="true"
                smtpPort="587"
                smtpServer="smtp.gmail.com"
                userName="my@account"
                password="mypassword" />
      </elmah>

      <connectionStrings>
        <add name="elmah-sql" connectionString="data source=(sqlserver); 
               database=elmahdb;
             integrated security=false;User ID=user;Password=password"/>
      </connectionStrings>
      <system.web>
        <compilation debug="true">
          <assemblies>
            <add assembly="Elmah, Version=1.0.10617.0, Culture=neutral, 
               PublicKeyToken=null"/>
          </assemblies>
        </compilation>
        <authentication mode="Windows"/>

        <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"/>
        </httpHandlers>
        <httpModules>
          <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, 
                System.Web.Extensions, Version=3.5.0.0, Culture=neutral, 
                PublicKeyToken=31BF3856AD364E35"/>
        </httpModules>
      </system.web>

      <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true">
          <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="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
          <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
          <add name="ErrorFilter" type="Elmah.ErrorFilterModule, 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" 
                       preCondition="integratedMode" 
               type="Elmah.ErrorLogPageFactory, Elmah"/>
        </handlers>
      </system.webServer>
    </configuration>

EDIT: Elmah = (Модулі та обробники журналів помилок)
http://code.google.com/p/elmah/


1
Аман: Ви припускаєте, що всі знають, що таке ELMAH. Я відредагував запитання, щоб надати посилання. Виправте це, якщо це не так.
— shahkalpesh

Думаю, вам, можливо, доведеться зареєструвати обробник / модуль на рівні IIS, я думаю, він буде працювати.
— shahkalpesh

1
Подивіться, чи це допомагає - msdn.microsoft.com/en-us/library/aa479332.aspx
— shahkalpesh

Дякую @shahkalpesh. Я справді завалений роботою! Хоча я думав, що це питання може допомогти і іншим, і зробив це спільнотою wiki.
— TheVillageIdiot

Дивно, але я спробував пропозиції без удачі! Найгірше, коли я намагався отримати доступ elmah.axd, IIS зависає.

Відповіді:


28

Спробуйте зареєструвати модулі та обробники в розділах "httphandlers" та "httpmodules" у <system.web>розділі:

    <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>

Yippe its working!!! It occurred to me also to put it there but I've not seen it in any online blogs solutions etc so I was bit sort of shy to do it.
— TheVillageIdiot

153

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>

For some reason, this got ELMAH working for me on a different server. Which is odd, as it should be identical to ours, yet we just have system.webserver declarations.
— Maximillian

2
Thanks, that really helped me out.
— stimms

1
Amazing, this answer saved me big time.
— Chris F

22
for those of you cutting and pasting from system.web to system.webserver, make sure you add the name attribute in the handlers section.
— Jason Watts

2
Thanks, it worked for me. But is this a bug? <system.web> is supposed to be for IIS6 while <system.webServer> is for IIS7+ per stackoverflow.com/questions/355261/…
— DeepSpace101

120

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.


1
This did it for me after verifying eyesnz's post.
— CitizenBane

4
Yea but don't forget to secure that page via authentication. Otherwise anyone can read your logs.
— driAn

well, Yes. 404 is "not found" but mostly when you fix 404 as marked answer you usually got 403.
— Jirapong

3
you need to add under sectiongroup name="elmah" <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
— Mhmd

You need to add this after the </configSections> tag
— Karl Glennon

12

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.


This absolutely worked for me as well. Thanks Peter.
— Lee Englestone

This was the fix for me, I am also on vs 2013, iis8.0, used nuget to install.
— James Bailey

This fixed it for me in VS 2015 on localhost in debug after using nuget to install ELMAH.
— SenseiHitokiri

I had this too. I've raised an issue with the project github.com/alexbeletsky/elmah-mvc/issues/89
— m.edmondson

Worked for me as well
— Dragos Durlut

11

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


nuget is really making developers life easier.
— TheVillageIdiot

Did just fine on my web.config
— Benj Sanders

9

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" />

0

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" />
Використовуючи наш веб-сайт, ви визнаєте, що прочитали та зрозуміли наші Політику щодо файлів cookie та Політику конфіденційності.
Licensed under cc by-sa 3.0 with attribution required.