ASP Errors
See log ASP errors with log4net or log ASP errors with health monitoring.
Errors
- Page level: Page_Error event (Server.ClearError if you don't want it to bubble up)
- Page level: Page directive <%@ Page ErrorPage="SpecificErrorPage.aspx" %>
- Application level: Application_Error() event in global.asax (NB error is InnerException as a HttpUnhandledException is wrapping it)
- Application level: web.config:
<system.web>
<customErrors mode="On" defaultRedirect="/Error.html">
<error statusCode="404" redirect="/Error.html"/>
<error statusCode="413" redirect="/UploadError.html"/>
</customErrors>
</system.web>To see the "yellow screen of death" always:
<system.web>
<customErrors mode="Off"/>
</system.web>
<system.webServer>
<httpErrors errorMode="Detailed"/>
</system.webServer> - IIS level: configuration/system.webServer/httpErrors[@existingResponse="PassThrough"]
May need to unlock: in C:\Windows\System32\inetsrvappcmd unlock config /section:httpErrors
For IIS 7.5+ Response.TrySkipIiisCustomErrors=true
Error Logging
NB: Web.config customErrors/@defaultRedirect can't log (implicit Server.ClearError)
Global.asax Application_Error. This can obviate the customErrors/@defaultRedirect directive if you Server.ClearError() and redirect. See an example with log4net or an example with asp 2 health monitoring.
In ASP 2, put WebEventProviders in the web.config. (Quickstart, msdn)
"All Errors" doesn't pick up handled errors. Including those handled by Server.ClearError in Global.Application_Error
Event Log
ASP.Net cannot by default create a event log source (unless you use the ASP.Net 2 Health Monitoring source). (KB- either create a registry entry for it, or use System.Diagnostics.EventLogInstaller).
Async Disconnect Errors (.net 4.5)
In .net 4.5 you can use async Task actions. Because they are async, disconnects trigger the standard escalation policy to terminate the process. Opps. Put this in Global.asax Application_Start:
//log and swallow the async disconnect errors "The remote host closed the connection. The error code is 0x80070057."
TaskScheduler.UnobservedTaskException += (sender, e) =>
{
e.SetObserved();
Trace.TraceError(e.Exception.ToString());
};