Session variables in Application_error not working

T

tshad

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 like
to get the list of the users Session Variables there were there at the time
of the error. But if I add the following line:

MyMessage.Body &= "Session Variable" & session("JobTitle") & vbCrLf

it goes back to the MS error page instead of my error page
(/PageError.aspx). If I don't have that line, I get my error page.

What is causing the problem and how can I get an the session variables?

Here is the Application_Error function:

Sub Application_Error(Sender As Object, E as EventArgs)
Dim LastException as String = Context.Error.ToString()
Dim exception As Exception = Server.GetLastError()
ExceptionLogger.Log(exception)

Dim MyMessage as New MailMessage
MyMessage.To = "(e-mail address removed)"
MyMessage.From = "(e-mail address removed)"
MyMessage.Subject = "Unhandled ASP.Net Error"
MyMessage.Body = vbCrLf & vbCrLf & "An Error was Generated on " & now &
vbCrLf & vbCrLf & _
"To see a list of Errors:
HTTP:\\www.staff.com\ad\showExceptions.aspx" & vbCrLf & vbCrLf & _
"Page: " & HTTPContext.Current.Request.Url.ToString()
& vbCrLf & vbCrLf

While Not exception Is Nothing
MyMessage.Body &= "Source: " & exception.Source & vbCrLf & _
"Message: " & exception.Message & vbCrLf & _
"Stack Trace: " & vbCrLf & exception.StackTrace &
vbCrLf & vbCrLf
exception = exception.InnerException
End While

MyMessage.Body &= "Session Variable" & session("JobTitle") & vbCrLf

SmtpMail.SmtpServer = Application("MailServer")
SmtpMail.Send(MyMessage)

Context.ClearError()
response.Redirect("/PageError.aspx")
End Sub


Thanks,

Tom
 
C

CJ

You must give the session a context as you did with the other stuff..

HTTPContext.Current.Session("x")
 
T

tshad

CJ said:
You must give the session a context as you did with the other stuff..

HTTPContext.Current.Session("x")

That was it.

But why do I need the context here and not in a normal .aspx page?

Thanks,

Tom
 
T

tshad

tshad said:
That was it.

I thought it was working, but apparently it wasn't.

If I have this in my global.asax:

MyMessage.Body &= "Session Variable: " &
HTTPContext.Current.session("JobTitle") & vbCrLf

It doesn't work.

If I have this (just commenting it out):
 
T

tshad

tshad said:
That was it.

Spoke too soon.

If I have the following in my Global.asax:

MyMessage.Body &= "Session Variable: " &
HTTPContext.Current.session("JobTitle") & vbCrLf

This doesn't work and causes the Global.asax to fail.

If I just comment it out like so:

' MyMessage.Body &= "Session Variable: " &
HTTPContext.Current.session("JobTitle") & vbCrLf

It works fine.

Do I need something else here?

Thanks,

Tom
 
T

tshad

I tried this:

MyMessage.Body &= "Number of Session Variable: " &
System.Web.HttpContext.Current.session("temp")

and it still doesn't work, but other articles say it should.

Tom
 
T

tshad

I give up.

I assume that you apparently cannot access the session variables in the
Global.asax file.

I know the session variables are the since I can see them from the page I
redirect to from the Global.asax. I have tracing turned on and all there
variables are there. Since any access to the session sends me to a MS error
page, I assume that they aren't accessable from there.

Tom
 
A

Alvin Bruney - ASP.NET MVP

I give up.
Yup, maybe you should.

But then again, if you want to take one last shot, produce a small
application that demonstrates the problem and post the code here for us to
see.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
 
Joined
Jul 17, 2006
Messages
3
Reaction score
0
Session object in application_onerror

Did you find a solution to this problem? I also seem to have the same issue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top