Raise the last exception on an ASP.NET error page

I have an error page here SiteError.aspx, and it is correctly configured in web.config to go there when unhandled exceptions are encountered.

I want to use this page to log the exception that caused it, because I only want to log errors that users encounter (i.e. if SiteError.aspxit ever comes across.)

This is the code I have:

In OnLoad(...)inSiteError.aspx

    Exception lastEx = Context.Server.GetLastError();
    if (lastEx != null)
        log.Error("A site error was encountered", lastEx);

However, my log never appears in my output, and if I breakpoint on line 2 (in this example), the execution of the code never stops (after throwing an exception for ASP.NET handling in the debugger.

+3
source share
1 answer

This can help you. http://support.microsoft.com/kb/306355

See "How to use the Web.config file."

I think you need to add Global.asax to your project and handle the error in the Application_Error method.

+1
source

Source: https://habr.com/ru/post/1745014/


All Articles