![]() |
|
|
|||||||
![]() |
ASP Net - ASP.NET 2.0 session availability in Global.asax? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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? > > > > > > > |
|
|
|
#3 |
|
Posts: n/a
|
SessionState is not available in PreRequestHandlerExecute
|
|
|
|
#4 |
|
Posts: n/a
|
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? > |
|