Issue with GetLastError() in Passing Application_Error to Custom Error Page

R

robertlair

I am having issues with a production server with the GetLastError()
method. Here is what I am doing:

Application_Error on Global ASAX:

Note: I am doing it this way (with ClearError) because while
researching, someone on a post said that Session state would not
persist unless I cleared the error... didn't make sense, but it also
didn't work before I put this in there too.

Exception ex = Server.GetLastError();
Server.ClearError();
Session["LastError"] = ex;
Response.Redirect("CustomErrorPage.aspx");

Then, on the Custom Error Page:

Exception ex = (Exception)Session["LastError"];
// displaying and emailing exception details

On my developer machine, this works just fine, but on the production
server the Session["LastError"] ALWAYS returns null. As a result, I
cannot get to any of the exception details. I also tried doing all of
this in the global asax, but there the GetLastError() is STILL null!
Makes no sense to me how on the Application_Error method the first line
of code is GetLastError() and it returns null. Any ideas?
 
S

S. Justin Gengo

I think you're clearing the error before you've placed it into a threadsafe
object.

In other words Server.ClearError(); is getting rid of the object stored in
Session also.

Try placing the error text into a string first such as:

String ex = Server.GetLastError().ToString;

Session["LastError"] = ex;

Then change ex on your custom error page to a string. (The string will
contain all the error text...)

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top