429,570 Members | 970 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,570 IT Pros & Developers. It's quick & easy.

# Session variables in Application_error not working

 P: n/a 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 = "tf*@aol.com" MyMessage.From = "tf*@ft.com" 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 Feb 20 '06 #1
8 Replies

 P: n/a You must give the session a context as you did with the other stuff.. HTTPContext.Current.Session("x") Feb 20 '06 #2

 P: n/a "CJ" wrote in message news:11**********************@o13g2000cwo.googlegr oups.com... 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 Feb 20 '06 #3

 P: n/a Because the .aspx page inherits from System.Web.UI.Page which gives it access to the Session. http://msdn.microsoft.com/library/de...classtopic.asp Feb 20 '06 #4

 P: n/a "tshad" wrote in message news:el**************@TK2MSFTNGP12.phx.gbl... "CJ" wrote in message news:11**********************@o13g2000cwo.googlegr oups.com... You must give the session a context as you did with the other stuff.. HTTPContext.Current.Session("x") 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): But why do I need the context here and not in a normal .aspx page? Thanks, Tom Feb 20 '06 #5

 P: n/a "tshad" wrote in message news:el**************@TK2MSFTNGP12.phx.gbl... "CJ" wrote in message news:11**********************@o13g2000cwo.googlegr oups.com... You must give the session a context as you did with the other stuff.. HTTPContext.Current.Session("x") 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 But why do I need the context here and not in a normal .aspx page? Thanks, Tom Feb 20 '06 #6

 P: n/a 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 "tshad" wrote in message news:ez**************@TK2MSFTNGP15.phx.gbl... "tshad" wrote in message news:el**************@TK2MSFTNGP12.phx.gbl... "CJ" wrote in message news:11**********************@o13g2000cwo.googlegr oups.com... You must give the session a context as you did with the other stuff.. HTTPContext.Current.Session("x") 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 But why do I need the context here and not in a normal .aspx page? Thanks, Tom Feb 21 '06 #7

 P: n/a 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 "tshad" wrote in message news:O3*************@tk2msftngp13.phx.gbl...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 "tshad" wrote in message news:ez**************@TK2MSFTNGP15.phx.gbl... "tshad" wrote in message news:el**************@TK2MSFTNGP12.phx.gbl... "CJ" wrote in message news:11**********************@o13g2000cwo.googlegr oups.com... You must give the session a context as you did with the other stuff.. HTTPContext.Current.Session("x") 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 But why do I need the context here and not in a normal .aspx page? Thanks, Tom Feb 21 '06 #8

 P: n/a > 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 ------------------------------------------------------- "tshad" wrote in message news:u1*************@TK2MSFTNGP09.phx.gbl... 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 "tshad" wrote in message news:O3*************@tk2msftngp13.phx.gbl...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 "tshad" wrote in message news:ez**************@TK2MSFTNGP15.phx.gbl... "tshad" wrote in message news:el**************@TK2MSFTNGP12.phx.gbl... "CJ" wrote in message news:11**********************@o13g2000cwo.googlegr oups.com...> You must give the session a context as you did with the other stuff..>> HTTPContext.Current.Session("x") 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 But why do I need the context here and not in a normal .aspx page? Thanks, Tom Feb 22 '06 #9

### This discussion thread is closed

Replies have been disabled for this discussion.