472,993 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Accessing session variable values from the 'Application_BeginRequest' handler

Stu
Hi,

I am trying to access session variable value from the
'Application_BeginRequest' handler in the global asax file but get the
message - 'Session state not available in this context'. I have tried
loading the current context using 'Dim context As HttpContext =
HttpContext.Current' but get the error 'Object reference not set to an
instance of an object'

Anyone know how you get at this?

Thanks in advance,

Stu

Code:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim context As HttpContext = HttpContext.Current
If Not IsNothing(context.Session("Test")) Then
context.Session("Test") = "Hello world!"
End If
End Sub
Nov 19 '05 #1
2 5392
Session state isn't loaded until later in the lifetime of the request. Instead
of Application_BeginRequest, build Application_PreRequestHandlerExecute --
this is the safest place to do your work prior to the page getting called.
The step where session is actually loaded in Application_AcquireRequestState,
so that's another option. Again, these are all in global.asax.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

I am trying to access session variable value from the
'Application_BeginRequest' handler in the global asax file but get the
message - 'Session state not available in this context'. I have tried
loading the current context using 'Dim context As HttpContext =
HttpContext.Current' but get the error 'Object reference not set to an
instance of an object'

Anyone know how you get at this?

Thanks in advance,

Stu

Code:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
Dim context As HttpContext = HttpContext.Current
If Not IsNothing(context.Session("Test")) Then
context.Session("Test") = "Hello world!"
End If
End Sub


Nov 19 '05 #2
Stu
Thanks - that worked great.

Stu

"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:51**********************@msnews.microsoft.com ...
Session state isn't loaded until later in the lifetime of the request.
Instead of Application_BeginRequest, build
Application_PreRequestHandlerExecute --
this is the safest place to do your work prior to the page getting called.
The step where session is actually loaded in
Application_AcquireRequestState, so that's another option. Again, these
are all in global.asax.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

I am trying to access session variable value from the
'Application_BeginRequest' handler in the global asax file but get the
message - 'Session state not available in this context'. I have tried
loading the current context using 'Dim context As HttpContext =
HttpContext.Current' but get the error 'Object reference not set to an
instance of an object'

Anyone know how you get at this?

Thanks in advance,

Stu

Code:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
Dim context As HttpContext = HttpContext.Current
If Not IsNothing(context.Session("Test")) Then
context.Session("Test") = "Hello world!"
End If
End Sub


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
3
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
2
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have...
3
by: Paul Daly (MCP) | last post by:
I'm trying to write a log file that captures the referring url if the request is a new session, and captures a querystring value if the user is browsing between pages on the website. When using...
5
by: news.microsoft.com | last post by:
Hi everyone, I need some help (may be in the form of some sample code) for the subject question. I have an ASP.NET/C# application. I need to do quite a few tasks when the session ends. I...
2
by: David Berman | last post by:
It seems that my site is losing session information when using Server.Transfer. I have a page called PictureGallery.aspx. It takes an argument which is an index id, so it would look like...
10
by: Nemisis | last post by:
Hi everyone, I am trying to create a custom error page, that the user gets shown when a error has occurred within my website. The code works perfectly, apart from when an invalid URL is typed...
5
by: aamirghanchi | last post by:
Hi, I need to know if anyone else came across this. The Session variable value I set in a sortCommand event handler of a datagrid does not hold on till the next sortcommand event handler and...
2
by: sony.m.2007 | last post by:
Hi, When i try to set a value for a session variable I'm getting a object refence not set error I tried two methods as below HttpContext.Current.Session.Add("AppStartTime", DateTime.Now);...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.