Re: Accessing SessionState in Application_Error

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



If the error is occurring there, then the problem is that you don't
have a valid session object. This is born out by the fact that you've
tried twice to write two different variables to the session, and both
of them raise the same exception.

So the next question I have for you is this: What is the exception
that is putting you in this exception handler in the first place?
Whatever it is, it's apparently occurring before you have a valid
session, or it's disconnecting the user from their session. I'd look
there.

Without a valid session, you won't be able to cache the exception
information in it. To prevent the NullReferenceException, wrap the
offending statement in a conditional, as follows (assuming VB.NET):

If Not HttpContext.Current.Session Is Nothing Then
HttpContext.Current.Session.Add("LastException", Exception)
End If

Hope this helps!

Mike

In order to get this error, i am trying to navigate to a page that
doesnt exist on my site ie. Home4.aspx. This causes the
application_Error sub to be called, but the session is empty/null. If
i create a standard page, and write Throw New Exception(), again, the
application_error code is called, but the session IS VALID, and i do
not get a NullReferenceException.

Why do you get a nullreferenceexception on a 404 error? Is it because
the page is not apart of your application, thus the session wont exist?

.



Relevant Pages

  • Re: Accessing SessionState in Application_Error
    ... You're describing a NullReferenceException. ... I *think* it's happening in the custom error page. ... it means that you either don't have a session or have a new ... HttpContext.Current.Session("LastException") = Exception ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Accessing SessionState in Application_Error
    ... have a valid session object. ... of them raise the same exception. ... To prevent the NullReferenceException, wrap the ... Wrap that code in an exception handler. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Postnuke XSS issues [correction]
    ... >As it turns out the Postnuke issue in particular is a red herring. ... The session ID is displayed in the popup ... If an attacker obtains a valid session ID of a regular ...
    (Bugtraq)
  • Re: Session expired or never started?
    ... > session is empty and they get bounced to the login page. ... > have a valid session ID because their session has timed out? ... You can however check if the user is sending a PHPSESSIONID, ...
    (comp.lang.php)
  • Re: session management- your opinion
    ... from another machine using a valid session ID. ... Not unless you can intercept the packets somewhere between the server and the client, or have access to the server file system. ... JDS Computer Training Corp. ...
    (comp.lang.php)