Click here to Skip to main content
16,019,983 members
Articles / Programming Languages / ASP
Alternative
Tip/Trick

Getting the last error in a custom error page

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
5 Jan 2011CPOL 7.2K   1   1
Would it not be easier to capture your Error in your Global.aspx page?void Application_Error(object sender, EventArgs e){ Exception lastError = Server.GetLastError(); if (lastError == null) { ErrorLog("An error occurred, but no error information is available"); ...
Would it not be easier to capture your Error in your Global.aspx page?

C#
void Application_Error(object sender, EventArgs e)
{
    Exception lastError = Server.GetLastError();
    if (lastError == null)
    {
       ErrorLog("An error occurred, but no error information is available");
    }
    else
    {
       ErrorLog(lastError.ToString());
    }
}


Regards

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralCompletely agree, you should always aim to minimise the code... Pin
Carl Reid10-Jan-11 5:26
Carl Reid10-Jan-11 5:26 
Completely agree, you should always aim to minimise the code on the actual error page itself, this will also help to ensure the error page does itself throw any errors. Ideally log the error in global then use the error page to indicate to the user that an error has occurred but do not attempt to do anything else on this page.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.