问题
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 >
回答1:
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:
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>
来源:https://stackoverflow.com/questions/11015013/when-i-browse-http-localhost8004-elmah-axd-it-generates-404-error