473,394 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Session variables in Application_error not working

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 1975
CJ
You must give the session a context as you did with the other stuff..

HTTPContext.Current.Session("x")

Feb 20 '06 #2
"CJ" <Ch*************@gmail.com> 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
CJ
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
"tshad" <tf*@dslextreme.com> wrote in message
news:el**************@TK2MSFTNGP12.phx.gbl...
"CJ" <Ch*************@gmail.com> 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
"tshad" <tf*@dslextreme.com> wrote in message
news:el**************@TK2MSFTNGP12.phx.gbl...
"CJ" <Ch*************@gmail.com> 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
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" <ts**********@ftsolutions.com> wrote in message
news:ez**************@TK2MSFTNGP15.phx.gbl...
"tshad" <tf*@dslextreme.com> wrote in message
news:el**************@TK2MSFTNGP12.phx.gbl...
"CJ" <Ch*************@gmail.com> 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
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" <ts**********@ftsolutions.com> 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" <ts**********@ftsolutions.com> wrote in message
news:ez**************@TK2MSFTNGP15.phx.gbl...
"tshad" <tf*@dslextreme.com> wrote in message
news:el**************@TK2MSFTNGP12.phx.gbl...
"CJ" <Ch*************@gmail.com> 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
> 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" <ts**********@ftsolutions.com> 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" <ts**********@ftsolutions.com> 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" <ts**********@ftsolutions.com> wrote in message
news:ez**************@TK2MSFTNGP15.phx.gbl...
"tshad" <tf*@dslextreme.com> wrote in message
news:el**************@TK2MSFTNGP12.phx.gbl...
"CJ" <Ch*************@gmail.com> 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 thread has been closed and replies have been disabled. Please start a new discussion.

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,...
9
by: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example...
1
by: Michael | last post by:
Hello, In my handled exceptions (using try/catch), I would like to be able to log certain variable values when an error occurs, to make debugging easier. I'm using the sub application_error in...
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...
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...
2
by: ronchese | last post by:
I'm noticing this since I started developing a website project: my session variables are getting empty! I did a real easy test, and I checked my session variable is getting empty!! What is...
4
by: BenCoo | last post by:
In my ASP.NET 2.0 application I have in the global.asax.file the following code Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when an unhandled error...
14
by: Rick | last post by:
We are in the process of testing a large web project that I converted from VS 2003 to VS 2005. Everything seems to be working except for a few minor things. But the main issue I have is this, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.