G
Guest
I need to be able to trap errors at the application level. I added this code
to the Global.asax file. The code I wrote is supposed to get the last error
that was generated and write to the event log as well as fire up my email
class and generate an email to send me the error. But no matter what I do, I
still get the icky looking yellow and white error screens.
I’ve turned on customErrors in the web.config but not default URL setting.
The pages don’t have Page_Error method in them so I would except the error to
move next up in the hierarchy which would be Application_Error. There are so
many pages in this project, I really cant trap general errors at the page
level. What am I doing wrong?????
protected void Application_Error(Object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string err ="Error Caught in Application_Error event\n" +
"Error in: " + Request.Url.ToString() +"\nError Message:" +
objErr.Message.ToString()+ "\nStack Trace:" + objErr.StackTrace.ToString();
EventLog.WriteEntry("Sample_WebApp",err,EventLogEntryType.Error);
Server.ClearError();
classes.email Email = new classes.email();
bool Status = Email.GenerateEmail("ERROR",null,err.ToString());
Response.Redirect("errorpage.aspx");
}
to the Global.asax file. The code I wrote is supposed to get the last error
that was generated and write to the event log as well as fire up my email
class and generate an email to send me the error. But no matter what I do, I
still get the icky looking yellow and white error screens.
I’ve turned on customErrors in the web.config but not default URL setting.
The pages don’t have Page_Error method in them so I would except the error to
move next up in the hierarchy which would be Application_Error. There are so
many pages in this project, I really cant trap general errors at the page
level. What am I doing wrong?????
protected void Application_Error(Object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string err ="Error Caught in Application_Error event\n" +
"Error in: " + Request.Url.ToString() +"\nError Message:" +
objErr.Message.ToString()+ "\nStack Trace:" + objErr.StackTrace.ToString();
EventLog.WriteEntry("Sample_WebApp",err,EventLogEntryType.Error);
Server.ClearError();
classes.email Email = new classes.email();
bool Status = Email.GenerateEmail("ERROR",null,err.ToString());
Response.Redirect("errorpage.aspx");
}