当我浏览 http:// localhost:8004 / elmah.axd 时,它会显示应用程序中发生的错误,但它也会生成404错误。我将如何阻止这404错误?
404错误的详细信息是:
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)
我的网络配置文件如下:
< 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 >
答案 0 :(得分:4)
我将如何阻止此404错误?
在您的网络应用程序中添加/favicon.ico
。当Google Chrome等现代浏览器请求网址时,他们会向/favicon.ico
发送额外的HTTP请求,以显示与此网页相关联的favicon。如果您的站点根目录中没有此类文件,则Web服务器将返回404,这是您在Elmah错误日志中观察到的内容。
尝试使用Internet Explorer浏览elmah.axd
,但不会看到404错误。
答案 1 :(得分:2)
或者,您可以将以下内容添加到web.config文件中的ELMAH configure部分,以忽略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>