Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - ASP.NET 2.0 session availability in Global.asax?

 
Thread Tools Search this Thread
Old 05-10-2006, 03:57 PM   #1
Default 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... 007064853919

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?








kingski
  Reply With Quote
Old 05-10-2006, 05:53 PM   #2
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
 
Posts: n/a
Default RE: ASP.NET 2.0 session availability in Global.asax?

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... 007064853919
>
> 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?
>
>
>
>
>
>
>

  Reply With Quote
Old 05-29-2006, 03:15 PM   #3
Jc Morin
 
Posts: n/a
Default Re: ASP.NET 2.0 session availability in Global.asax?

SessionState is not available in PreRequestHandlerExecute

  Reply With Quote
Old 05-30-2006, 02:33 AM   #4
Brock Allen
 
Posts: n/a
Default Re: ASP.NET 2.0 session availability in Global.asax?

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?
>



  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump