471,354 Members | 1,487 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 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 5144
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Paul Daly (MCP) | last post: by
5 posts views Thread by news.microsoft.com | last post: by
10 posts views Thread by Nemisis | last post: by
5 posts views Thread by aamirghanchi | last post: by
2 posts views Thread by sony.m.2007 | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.