469,628 Members | 1,024 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,628 developers. It's quick & easy.

Application_Error() cannot access Session if the error is HTTP 404

4
I have the following code in my global.asax file:
Expand|Select|Wrap|Line Numbers
  1. void Application_Error(object sender, EventArgs e) 
  2. {
  3.      string ex = Server.GetLastError().ToString();
  4.      HttpContext.Current.Session["HttpContext_ERROR"] = HttpContext.Current;
  5.      HttpContext.Current.Session["LastError"] = ex;
  6.      // this just logs various info about the error
  7.      ErrorLogger.LogError("Uncaught exception", ex, HttpContext.Current);
  8.      Server.ClearError();
  9. }
This works just fine for HTTP 500 (Server Error) errors, but if it's a HTTP 404 (File Not Found) error, the Session is always null. Why? Is there any way to read or write to the Session in Application_Error for a 404?
Dec 6 '07 #1
1 5986
Frinavale
9,735 Expert Mod 8TB
I have the following code in my global.asax file:
Expand|Select|Wrap|Line Numbers
  1. void Application_Error(object sender, EventArgs e) 
  2. {
  3.      string ex = Server.GetLastError().ToString();
  4.      HttpContext.Current.Session["HttpContext_ERROR"] = HttpContext.Current;
  5.      HttpContext.Current.Session["LastError"] = ex;
  6.      // this just logs various info about the error
  7.      ErrorLogger.LogError("Uncaught exception", ex, HttpContext.Current);
  8.      Server.ClearError();
  9. }
This works just fine for HTTP 500 (Server Error) errors, but if it's a HTTP 404 (File Not Found) error, the Session is always null. Why? Is there any way to read or write to the Session in Application_Error for a 404?
The HttpContext object is created by ASP.NET during the page request. Since no page was found, no HttpContext Object can be created; therefore, no Session can exist when a 404 error occurs.

-Frinny
Dec 6 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Greg Burns | last post: by
reply views Thread by DalePres | last post: by
10 posts views Thread by Nemisis | last post: by
8 posts views Thread by bmukulu | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.