Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session variables in Application_onError

Status
Not open for further replies.

vwhite

Programmer
Oct 4, 2001
87
0
0
AU
Hello all,

I have a procedure in Application_onError in the global.asax file that sends an email to the Administrator and then redirects to an error page.

In the email it also sends some information that has been retreived from session variables.

This used to work fine. Now it doesn't - the only thing I can think of that has changed is that we upgraded from .NET 1.1 to 2.0

This is how I am accessing the session variables
Dim ClientID as string = HttpContext.Current.Session("client_id")

And this is the error message I get
Object reference not set to an instance of an object.

Can anyone help with this problem?

Thanks




Vicky....

"I used to have a handle on life...then it broke
 
Are you sure that is the line that the error occurs on? If so, then the session variable is NOTHING.
 
It is more work, but you would be better off including error handlers on each page's methods. It gets you a lot more fine-grained error reporting.

Brian Begy
BugSentry - Automatic error reporting for .NET and COM
 
Try:

Dim ClientID as string = HttpContext.Current.Session("client_id").ToString
 
I am certain that the error occurs on that line and I know that the session variable exists as I am using it throughout the application.

I have also tried

Dim ClientID as string = HttpContext.Current.Session("client_id").ToString

and I get the same error

If try
Dim ClientID as string = Session("client_id").ToString

I get the error
Session state is not available in this context.


Vicky....

"I used to have a handle on life...then it broke
 
Ok then, try this!

Dim o As Object = HttpContext.Current.Session.Item("client_id")
Dim ClientID as String = Nothing

If Not o Is Nothing Then
ClientID = o.ToString
Else
Response.Write("Session has probably Expired or Item cannot be found..")
End If


:)
 
it dies as soon as it hits
Dim o As Object = HttpContext.Current.Session.Item("client_id")

with the same error message
Object reference not set to an instance of an object.


Vicky....

"I used to have a handle on life...then it broke
 
try accessing some other session variable. does it throw an error for that also???

Known is handfull, Unknown is worldfull
 
yep any session variable...

Vicky....

"I used to have a handle on life...then it broke
 
try this,
dim intTheCount as integer=HttpContext.Current.Session.Count

mark it for debugging, see wht happens.wht value do u get for that???




Known is handfull, Unknown is worldfull
 
I get the same error
Object reference not set to an instance of an object

Excuse my ignorance - but I don't know how to mark it for debuggging. I have to use Dreamweaver and I have not worked out how to do that.

I have a try, catch block - which shows me the error. I test be taking the line out to see if I still get the error.



Vicky....

"I used to have a handle on life...then it broke
 
>>Excuse my ignorance - but I don't know how to mark it for debuggging. I have to use Dreamweaver and I have not worked out how to do that.


no issues. i started .NET programming that way only. i guess we need to go much more deeper.

try this:
HttpContext.Current.Response.Write("ASD")

see if there is any error in that line. I now want to make sure that the error is not with the Context object...

Known is handfull, Unknown is worldfull
 
thanks for sticking with me here...

HttpContext.Current.Response.Write("ASD")

works fine

Vicky....

"I used to have a handle on life...then it broke
 
try this:
HttpContext.Current.Response.Write(HttpContext.Current.Session)

now what happens?


Known is handfull, Unknown is worldfull
 
no error - but also nothing is displayed.

Vicky....

"I used to have a handle on life...then it broke
 
very strange,

try this:
HttpContext.Current.Response.Write(HttpContext.Current.Session.Count)

its the same stmt as above, now if it gives an error then lets try pushing the code to an ASPX file, so that we can debug better...


Known is handfull, Unknown is worldfull
 
Object reference not set to an instance of an object.

do you mean creating a code behind file for the global.asax file?

Vicky....

"I used to have a handle on life...then it broke
 
lets shift the code to an ASPX code behind file.

try this in Page_Load of any ASPX file:

HttpContext.Current.Response.Write(HttpContext.Current.Session.Count)

does it give an error? seems like the ASAX file is unable to get session values...

Known is handfull, Unknown is worldfull
 
ok I have put all the code in a code behind file, which works until I add the

HttpContext.Current.Response.Write(HttpContext.Current.Session.Count)

and I get the same error again...

Vicky....

"I used to have a handle on life...then it broke
 
tried putting
HttpContext.Current.Response.Write(HttpContext.Current.Session.Count)

in the page_load of an aspx file

and it displays fine







Vicky....

"I used to have a handle on life...then it broke
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top