473,320 Members | 1,969 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,320 software developers and data experts.

Session doesn't work in Application_Error in Global.aspx

I have a general error page that I configured in web.config as
<customErrors mode="On" defaultRedirect="CRDefaultError.aspx" />
This error page comes up whenever an error occurs outside of any try/catch blocks.

This page has a text box in it that I would like to fill with relevant information about the error. I am trying to put the
Server.GetLastError().ToString() in there. It did not work on the page, and I read somewhere that I should create a session
variable in the Application_Error event in Global.aspx. My problem is that if I try to create a session variable in
Application_Error, it throws another error!

So, is there anyway that I can simply grab the Server.GetLastError().ToString() and get to it in my custom error page?

Thanks.

Mike


Nov 18 '05 #1
3 3187
Hi Mike,
Use your Server.GetLastError() in Application_Error event handler in
Global.asax.cs. and store it in a Session variable there.
protected void Application_Error(Object sender, EventArgs e)

{

Exception last_Error=Server.GetLastError();

if(last_Error!=null)

{

Session["last_Error"]=last_Error.ToString();

// You can redirect to your custom error page from here and can access the
Session variable Session["last_Error"] from there.

Response.Redirect("CRDefaultError.aspx");

}

Hope this helps.

Regards,

Marshal Antony

..NET Developer

http://www.dotnetmarshal.com



"Mike Malter" <mi********@nospam.com> wrote in message
news:uG**************@TK2MSFTNGP11.phx.gbl...
I have a general error page that I configured in web.config as
<customErrors mode="On" defaultRedirect="CRDefaultError.aspx" />
This error page comes up whenever an error occurs outside of any try/catch blocks.
This page has a text box in it that I would like to fill with relevant information about the error. I am trying to put the Server.GetLastError().ToString() in there. It did not work on the page, and I read somewhere that I should create a session variable in the Application_Error event in Global.aspx. My problem is that if I try to create a session variable in Application_Error, it throws another error!

So, is there anyway that I can simply grab the Server.GetLastError().ToString() and get to it in my custom error page?
Thanks.

Mike

Nov 18 '05 #2
Marshal,

Thanks. I'll try this.

Mike

"Marshal Antony" <do***********@yahoo.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi Mike,
Use your Server.GetLastError() in Application_Error event handler in
Global.asax.cs. and store it in a Session variable there.
protected void Application_Error(Object sender, EventArgs e)

{

Exception last_Error=Server.GetLastError();

if(last_Error!=null)

{

Session["last_Error"]=last_Error.ToString();

// You can redirect to your custom error page from here and can access the
Session variable Session["last_Error"] from there.

Response.Redirect("CRDefaultError.aspx");

}

Hope this helps.

Regards,

Marshal Antony

.NET Developer

http://www.dotnetmarshal.com



"Mike Malter" <mi********@nospam.com> wrote in message
news:uG**************@TK2MSFTNGP11.phx.gbl...
I have a general error page that I configured in web.config as
<customErrors mode="On" defaultRedirect="CRDefaultError.aspx" />
This error page comes up whenever an error occurs outside of any try/catch

blocks.

This page has a text box in it that I would like to fill with relevant

information about the error. I am trying to put the
Server.GetLastError().ToString() in there. It did not work on the page,

and I read somewhere that I should create a session
variable in the Application_Error event in Global.aspx. My problem is

that if I try to create a session variable in
Application_Error, it throws another error!

So, is there anyway that I can simply grab the

Server.GetLastError().ToString() and get to it in my custom error page?

Thanks.

Mike


Nov 18 '05 #3
Marshal,

The problem here is still the same, whenever I try to assign a value to a session variable in the Application_OnError event I get
another error.

Any thoughts?

Thanks.

Mike

"Marshal Antony" <do***********@yahoo.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi Mike,
Use your Server.GetLastError() in Application_Error event handler in
Global.asax.cs. and store it in a Session variable there.
protected void Application_Error(Object sender, EventArgs e)

{

Exception last_Error=Server.GetLastError();

if(last_Error!=null)

{

Session["last_Error"]=last_Error.ToString();

// You can redirect to your custom error page from here and can access the
Session variable Session["last_Error"] from there.

Response.Redirect("CRDefaultError.aspx");

}

Hope this helps.

Regards,

Marshal Antony

.NET Developer

http://www.dotnetmarshal.com



"Mike Malter" <mi********@nospam.com> wrote in message
news:uG**************@TK2MSFTNGP11.phx.gbl...
I have a general error page that I configured in web.config as
<customErrors mode="On" defaultRedirect="CRDefaultError.aspx" />
This error page comes up whenever an error occurs outside of any try/catch

blocks.

This page has a text box in it that I would like to fill with relevant

information about the error. I am trying to put the
Server.GetLastError().ToString() in there. It did not work on the page,

and I read somewhere that I should create a session
variable in the Application_Error event in Global.aspx. My problem is

that if I try to create a session variable in
Application_Error, it throws another error!

So, is there anyway that I can simply grab the

Server.GetLastError().ToString() and get to it in my custom error page?

Thanks.

Mike


Nov 18 '05 #4

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

Similar topics

1
by: Greg Burns | last post by:
I am trying to write a global custom error page. I thought I would jot down some of what I've learned so far... At first I just used the default customErrors section with a defaultRedirect tag,...
9
by: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example...
0
by: DalePres | last post by:
I have an error handling page that is called by Global.ASAX in the Application_Error handler. When I test Session.Count in Application_Error, it has a count of 2 and I can access the two session...
0
by: Mae | last post by:
Dear all, I having a problem here. The situation is as follow, I have a web system with is using C#, if error occur it will capture the error in Global.asax.cs in "Application_Error" and it will...
8
by: tshad | last post by:
I have an Application_Error function in my Global.asax function that works fine until I try to access my Session variables. I am emailing the results to myself whenever I get an error and would...
2
by: Daflookie | last post by:
For one reason or another I am unable to access Session contents in my asp.net application via the global.asax's Application_Error event. I can pull this exact code snippet below out of...
8
by: bmukulu | last post by:
Hi, I am trying to add some error handling in a Global.asax file. I am declaring a session variable within the Application_Error procedure. However, everytime i try to pass something into the...
4
by: BenCoo | last post by:
In my ASP.NET 2.0 application I have in the global.asax.file the following code Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when an unhandled error...
14
by: Rick | last post by:
We are in the process of testing a large web project that I converted from VS 2003 to VS 2005. Everything seems to be working except for a few minor things. But the main issue I have is this, I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.