Rhys666
Programmer
- May 20, 2003
- 1,106
I hate session objects, I hate default error pages - they just don't work properly!!! Yes I'm currently very frustrated...
I'm trying to capture and display errors on a generic page if they're not handled as it's simply not possible to cope with all exception types in every try...catch block.
I've done this previously by playing with Global.asax.cs, adding functionality to protected void Application_Error as below;
then redirecting the page to my error page, reading the error from the session object and simply writing it to a control. I.e.,
However, i'm currently getting a problem from the above. I can set up breakpoints so after I've added the error string to the session object I can retrieve it (?Session["Error"]) in the Command Window (in VS). However, when the page transfers to the generic error page, (which by stepping thru' I can see does happen after the errors been written to the session object), the Session["Error"] object evaluates as null - where has it gone?
Yes all the pages are part of the same project and solution, even the same namespace.
Even writing to a Session object from the page on which the error originates doesn't help as the session object evaluates as null by the time I get to my error page - any idea's, thoughts, workarounds or alternative solutions?
Just to confuse the issue I know the above functionality can work as I've had it working exactly as set out above in a different web application at a different company - hence some of my frustration at the moment!
Thanks in advance...
Rhys
""Vampireware /n/, a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."
My Home
I'm trying to capture and display errors on a generic page if they're not handled as it's simply not possible to cope with all exception types in every try...catch block.
I've done this previously by playing with Global.asax.cs, adding functionality to protected void Application_Error as below;
Code:
protected void Application_Error(Object sender, EventArgs e)
{
// At this point we have information about the error
HttpContext ctx = HttpContext.Current;
Exception exception = ctx.Server.GetLastError();
string errorInfo =
"<br>Offending URL: " + ctx.Request.Url.ToString() + "<br>" +
"<br>Source: " + exception.Source + "<br>" +
"<br>Inner Exception: " + exception.InnerException + "<br>" +
"<br>Message: " + exception.Message + "<br>" +
"<br>Stack trace: " + exception.StackTrace;
Session.Add("Error",errorInfo);
// To let the page finish running we can clear the error
// ctx.Server.ClearError ();
}
then redirecting the page to my error page, reading the error from the session object and simply writing it to a control. I.e.,
Code:
if (Session["Error"] != null)
{
this.lblError.Text = Session["Error"].ToString();
Session.Remove("Error");
}
However, i'm currently getting a problem from the above. I can set up breakpoints so after I've added the error string to the session object I can retrieve it (?Session["Error"]) in the Command Window (in VS). However, when the page transfers to the generic error page, (which by stepping thru' I can see does happen after the errors been written to the session object), the Session["Error"] object evaluates as null - where has it gone?
Yes all the pages are part of the same project and solution, even the same namespace.
Even writing to a Session object from the page on which the error originates doesn't help as the session object evaluates as null by the time I get to my error page - any idea's, thoughts, workarounds or alternative solutions?
Just to confuse the issue I know the above functionality can work as I've had it working exactly as set out above in a different web application at a different company - hence some of my frustration at the moment!
Thanks in advance...
Rhys
""Vampireware /n/, a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."
My Home