469,927 Members | 1,395 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

ASP.NET 2.0 session availability in Global.asax?

I have a web site created with ASP.NET 1.1. availability

Global.asax:

protected void Application_PreRequestHandlerExecute(Object sender, EventArgs
e)

{

SetCulture();

}

private void SetCulture()

{

string culturePref =
(string)ConfigurationSettings.AppSettings["DefaultCulture"];

if (Session["My_Session"] != null &&
Session["My_Session"].ToString().Length > 0)

culturePref =
Session["My_Session"].ToString();

Bla bla .

}

After migrating this web site to ASP.NET 2.0 in event viewer start appears
this:

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Event code: 3005

Event message: An unhandled exception has occurred.

Event time: 10.05.2006 16:24:07

Event time (UTC): 10.05.2006 14:24:07

Event ID: 6d22d64bd6174ea297a527bf2953c52b

Event sequence: 27

Event occurrence: 2

Event detail code: 0

Application information:

Application domain: /LM/W3SVC/2040315736/Root-2-127917444735263147

Trust level: Full

Application Virtual Path: /

Application Path: D:\Inetpub\www.luup.com\

Machine name: VINSON

Process information:

Process ID: 5352

Process name: w3wp.exe

Account name: NT AUTHORITY\NETWORK SERVICE

Exception information:

Exception type: HttpException

Exception message: Session state is not available in this context.

Request information:

Request URL:
https://www.vinson.com/webresource.a...75007064853919

Request path: /webresource.axd

User host address: 191.128.1.222

User:

Is authenticated: False

Authentication Type:

Thread account name: NT AUTHORITY\NETWORK SERVICE

Thread information:

Thread ID: 23

Thread account name: NT AUTHORITY\NETWORK SERVICE

Is impersonating: False

Stack trace: at System.Web.HttpApplication.get_Session()

at MyComp.Web.MyCompWeb.Global.SetCulture()

at
MyComp.Web.MyCompWeb.Global.Application_PreRequest HandlerExecute(Object
sender, EventArgs e)

at
System.Web.HttpApplication.SyncEventExecutionStep. System.Web.HttpApplication.IExecutionStep.Execute( )

at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

What is the first place /method/ in which is possible to access session in
Global.asax?

Any ideas what other can cause this exception?


May 10 '06 #1
3 3578
In ASP.NET 2.0, the Session object is not "Live" until something has been
added to it.
I'm not sure if its also available in PreRequestHandlerExcute either, but
this should help.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"kingski" wrote:
I have a web site created with ASP.NET 1.1. availability

Global.asax:

protected void Application_PreRequestHandlerExecute(Object sender, EventArgs
e)

{

SetCulture();

}

private void SetCulture()

{

string culturePref =
(string)ConfigurationSettings.AppSettings["DefaultCulture"];

if (Session["My_Session"] != null &&
Session["My_Session"].ToString().Length > 0)

culturePref =
Session["My_Session"].ToString();

Bla bla .

}

After migrating this web site to ASP.NET 2.0 in event viewer start appears
this:

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Event code: 3005

Event message: An unhandled exception has occurred.

Event time: 10.05.2006 16:24:07

Event time (UTC): 10.05.2006 14:24:07

Event ID: 6d22d64bd6174ea297a527bf2953c52b

Event sequence: 27

Event occurrence: 2

Event detail code: 0

Application information:

Application domain: /LM/W3SVC/2040315736/Root-2-127917444735263147

Trust level: Full

Application Virtual Path: /

Application Path: D:\Inetpub\www.luup.com\

Machine name: VINSON

Process information:

Process ID: 5352

Process name: w3wp.exe

Account name: NT AUTHORITY\NETWORK SERVICE

Exception information:

Exception type: HttpException

Exception message: Session state is not available in this context.

Request information:

Request URL:
https://www.vinson.com/webresource.a...75007064853919

Request path: /webresource.axd

User host address: 191.128.1.222

User:

Is authenticated: False

Authentication Type:

Thread account name: NT AUTHORITY\NETWORK SERVICE

Thread information:

Thread ID: 23

Thread account name: NT AUTHORITY\NETWORK SERVICE

Is impersonating: False

Stack trace: at System.Web.HttpApplication.get_Session()

at MyComp.Web.MyCompWeb.Global.SetCulture()

at
MyComp.Web.MyCompWeb.Global.Application_PreRequest HandlerExecute(Object
sender, EventArgs e)

at
System.Web.HttpApplication.SyncEventExecutionStep. System.Web.HttpApplication.IExecutionStep.Execute( )

at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

What is the first place /method/ in which is possible to access session in
Global.asax?

Any ideas what other can cause this exception?


May 10 '06 #2
SessionState is not available in PreRequestHandlerExecute

May 29 '06 #3
Session is available in PreRequesthandlerExecute, contrary to what others
have posted.

The problem is that your code is being executed for every request into the
server, and some requests (like ones for WebResourxe.axd) don't utlilize
Session (because the handler doesn't implement IRequireSessionState). So
change your code to only access Session if that request has access to it.
Change your code to do this:

protected void Application_PreRequestHandlerExecute(Object sender, EventArgs
e)

{

if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState)
SetCulture();

}

-Brock
http://staff.develop.com/ballen

I have a web site created with ASP.NET 1.1. availability

Global.asax:

protected void Application_PreRequestHandlerExecute(Object sender,
EventArgs e)

{

SetCulture();

}

private void SetCulture()

{

string culturePref =
(string)ConfigurationSettings.AppSettings["DefaultCulture"];

if (Session["My_Session"] != null &&
Session["My_Session"].ToString().Length > 0)

culturePref =
Session["My_Session"].ToString();

Bla bla .

}

After migrating this web site to ASP.NET 2.0 in event viewer start
appears this:

----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------

Event code: 3005

Event message: An unhandled exception has occurred.

Event time: 10.05.2006 16:24:07

Event time (UTC): 10.05.2006 14:24:07

Event ID: 6d22d64bd6174ea297a527bf2953c52b

Event sequence: 27

Event occurrence: 2

Event detail code: 0

Application information:

Application domain: /LM/W3SVC/2040315736/Root-2-127917444735263147

Trust level: Full

Application Virtual Path: /

Application Path: D:\Inetpub\www.luup.com\

Machine name: VINSON

Process information:

Process ID: 5352

Process name: w3wp.exe

Account name: NT AUTHORITY\NETWORK SERVICE

Exception information:

Exception type: HttpException

Exception message: Session state is not available in this context.

Request information:

Request URL:
https://www.vinson.com/webresource.a...UhORWyw2&t=632
775007064853919

Request path: /webresource.axd

User host address: 191.128.1.222

User:

Is authenticated: False

Authentication Type:

Thread account name: NT AUTHORITY\NETWORK SERVICE

Thread information:

Thread ID: 23

Thread account name: NT AUTHORITY\NETWORK SERVICE

Is impersonating: False

Stack trace: at System.Web.HttpApplication.get_Session()

at MyComp.Web.MyCompWeb.Global.SetCulture()

at
MyComp.Web.MyCompWeb.Global.Application_PreRequest HandlerExecute(Objec
t sender, EventArgs e)

at
System.Web.HttpApplication.SyncEventExecutionStep. System.Web.HttpAppli
cation.IExecutionStep.Execute()

at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step,
Boolean& completedSynchronously)

----------------------------------------------------------------------
----------------------------------------------------------------------
----------------------------------------------------

What is the first place /method/ in which is possible to access
session in Global.asax?

Any ideas what other can cause this exception?

May 30 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Pavils Jurjans | last post: by
5 posts views Thread by Pross | last post: by
4 posts views Thread by Kim Bach Petersen | last post: by
1 post views Thread by Raghu | last post: by
3 posts views Thread by dejavue82 | last post: by
2 posts views Thread by DamienS | last post: by
6 posts views Thread by =?Utf-8?B?UGF1bA==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.