2

当我浏览http://localhost:8004/elmah.axd时,它会显示应用程序中发生的错误,但也会生成 404 错误。我将如何停止这个 404 错误?

404错误的详细信息是:

    System.Web.HttpException (0x80004005):文件不存在。
   在 System.Web.StaticFileHandler.GetFileInfo(字符串 virtualPathWithPathInfo,字符串物理路径,HttpResponse 响应)
   在 System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext 上下文,字符串 overrideVirtualPath)
   在 System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext 上下文,AsyncCallback 回调,对象状态)
   在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   在 System.Web.HttpApplication.ExecuteStep(IExecutionStep 步骤,Boolean& completedSynchronously)
    

我的网络配置文件是这样的:

    <配置>
  <配置节>
    <sectionGroup 名称="elmah" >
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
    </section组>
  </ configSections >

  <系统.web>
        < 编译调试="true" targetFramework="4.0" />

        <http处理程序>
          < add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
        </ httpHandlers >

        <http模块>
          < add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
        </ http模块>

        <身份验证模式="表单" >
          <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
        </认证>
    …………
    …………
  </system.web>

  <系统.web服务器>
        < 模块 runAllManagedModulesForAllRequests="true" />
        < 验证 validateIntegratedModeConfiguration="false" />
        < 模块 >
          < add name="Elmah.ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
        </模块>
        <处理程序>
          < add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
        </ 处理程序 >
  </system.webServer>

  <埃尔玛>
        <安全允许远程访问="0" />
        <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/ErrorLogs" />
  </ 埃尔玛 >

</配置>

4

2 回答 2

4

我将如何停止这个 404 错误?

将一个添加/favicon.ico到您的 Web 应用程序。当现代浏览器(例如 Google Chrome)请求 url 时,它们会发送一个额外的 HTTP 请求/favicon.ico以显示与该页面关联的网站图标。如果您的站点根目录中没有此类文件,则 Web 服务器将返回 404,这是您在 Elmah 错误日志中观察到的内容。

例如,尝试elmah.axd使用 Internet Explorer 浏览您的,您将不会看到这样的 404 错误。

于 2012-06-14T06:07:37.077 回答
2

或者,您可以将以下内容添加到 web.config 文件中的 ELMAH 配置部分,以忽略 favicon.ico 请求。

<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>
于 2012-06-29T15:08:09.143 回答