472,785 Members | 1,267 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 6265
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

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

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,...
3
by: Mike Malter | last post by:
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...
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...
1
by: robertlair | last post by:
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...
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...
10
by: Nemisis | last post by:
Hi everyone, I am trying to create a custom error page, that the user gets shown when a error has occurred within my website. The code works perfectly, apart from when an invalid URL is typed...
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...
1
by: jobs | last post by:
I'm forcing an error/exception in one page as follows Protected Overrides Sub OnLoad(ByVal e As EventArgs) Dim badthing As New Exception("XXX") Throw badthing End Sub And attempting to set...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.