2
votes

When I browse http://localhost:8004/elmah.axd it shows the errors that occurred in the application, but it also generates 404 error. How I will stop this 404 error?

Details of 404 error is:

    System.Web.HttpException (0x80004005): File does not exist.
   at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
   at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath)
   at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    

My web config file is like:

    < configuration >
  < configSections >
    < sectionGroup name="elmah" >
      < section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      < section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
    </ sectionGroup >
  </ configSections >

  < system.web>
        < compilation debug="true" targetFramework="4.0" />

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

        < httpModules>
          < add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
        </ httpModules>

        < authentication mode="Forms" >
          < forms loginUrl="~/Account/Login.aspx" timeout="2880" />
        </ authentication >
    ..........
    ..........
  </ system.web >

  < system.webServer >
        < modules runAllManagedModulesForAllRequests="true" />
        < validation validateIntegratedModeConfiguration="false" />
        < modules >
          < add name="Elmah.ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
        </ modules >
        < handlers >
          < add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
        </ handlers >
  </ system.webServer >

  < elmah>
        < security allowRemoteAccess="0" />
        < errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/ErrorLogs" />
  </ elmah >

</ configuration >

2

2 Answers

4
votes

How I will stop this 404 error?

Add a /favicon.ico to your web application. When modern browsers such as Google Chrome request an url, they send an additional HTTP request to /favicon.ico in order to display the favicon associated to this page. If you don't have such file in the root of your site the web server will return 404 which is what you are observing in the Elmah error log.

Try for example browsing your elmah.axd with Internet Explorer and you won't see such 404 errors.

2
votes

Alternately you could add the following to the ELMAH configure section in your web.config file to ignore the favicon.ico requests.

<elmah>

 ...

<errorFilter>
  <!--    Do not capture 404 errors for favicon.ico file requests -->
  <test>
    <and>
      <equal binding="HttpStatusCode" value="404" type="Int32" />
      <regex binding="Context.Request.ServerVariables['URL']" pattern="/favicon.ico(\z|\?)" />
    </and>
  </test>
</errorFilter>

...

</elmah>