How to obtain error statusCode form Server.GetLastError()?

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I use GenericErrorPage.aspx for the redirect page when some error occur.
I want to show some different according error statusCode .

How can I get error statusCode form Server.GetLastError()?
 
What do you mean by 'statusCode'

Server.GetLastError returns a System.Exception object, you will have to cast
to the required exception type (if there is one).

HTH

Ollie Riches
 
Thanks, When error occur, I redirect usr the a error page.
I want to show custom error message to user.

How can I cast the
Server.GetLastError() to the required exception type ?
 
Here's a sample handler (global.asax):

void Application_Error(object sender, EventArgs e)
{
//get reference to the source of the exception chain
Exception ex = Server.GetLastError().GetBaseException();

EventLog.WriteEntry("MyWeb",
"MESSAGE: " + ex.Message +
"\nSOURCE: " + ex.Source +
"\nFORM: " + Request.Form.ToString() +
"\nQUERYSTRING: " + Request.QueryString.ToString() +
"\nTARGETSITE: " + ex.TargetSite +
"\nSTACKTRACE: " + ex.StackTrace,
EventLogEntryType.Error);

//Your other cool code here
}

--Peter
 
Back
Top