473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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?

Nov 19 '05 #1
1 2403
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

<ro********@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
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?

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: SilverlineDesign | last post by:
I am having trouble using Server.GetLastError() on my asp.net pages. I defines a standard error page in my web.config to handle all site errors, but the page that is supposed to handle the error...
3
by: ad | last post by:
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()?
1
by: Christopher | last post by:
Try using the Application_Error() event in Global.asax. The context of the error will be available here. Your application is handling the error, and thus there is no LastError to Get. hth,...
1
by: Dave | last post by:
Hi I want to know if it's possible to user Server.GetLastError() in my AppError.aspx below? The GetLastError is not available here and returns null. I'm using Application_Error event to send an...
6
by: José Joye | last post by:
Hello, I'm currently reading the MS Developing Web applications with c# (and VB.net). In the chapter related to Error management, there is a sample about "Page-Level Error Pages" eg: In my...
4
by: VK | last post by:
Hello, I am trying to get the last occured error via the following code: Sub Page_Load(...) Dim zero As Integer = 0 Try Dim err As Integer = 10 / zero Catch ex As Exception
6
by: Matt | last post by:
Can anyone give me a good reason to use BOTH application scope Page_Error and the page scope Page_Error when trapping errors in a web application? Is there any real benefit to using the Page_Error...
2
by: Seguros Catatumbo | last post by:
Hello guys, i am trying to port my custom asp 3.0 error page to asp.net. I want to disable debugging in my asp.net projects but i want to show the users a pretty page but that page should send me...
1
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
I have a web app that handles errors in the Gloabal.ascx's Application_Error(). It does some logging etc in there and if it throws an error, I want the app to display a static html splash page...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.