473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 3722
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Larry Woods | last post by:
I have a site that works fine for days, then suddenly, I start getting ASP 0115 errors with an indication that session variables IN SEPARATE SESSIONS have disappeared! First, for background...
3
by: Pavils Jurjans | last post by:
Hello, I am looking for solution to assign the Session.onEnd event handler dynamically, at runtime, without using global.asax file. I am a bit sceptic wether that is possible, however I thought...
5
by: Pross | last post by:
I've got an ASP.NET application and I need some information on every page like the user's name as well as a collection listing which sections of the application the user has access to. I could...
4
by: Kim Bach Petersen | last post by:
I would like to record user behavior data stored in session variables. Since the data is modified throughout each session it seemed obvious to store the data when the session terminates - using...
1
by: Raghu | last post by:
The global.asax page can have an event handler for AcquireRequestState. This is where a session can be accessed for the first time before the control ends up in the target page itself. However...
8
by: tshad | last post by:
I have an Application_Error function in my Global.asax function that works fine until I try to access my Session variables. I am emailing the results to myself whenever I get an error and would...
3
by: dejavue82 | last post by:
Hi, Is it possible to read from a Session object in one of the Global.asax events? I'm wondering, since I'm not sure if there is one instance of Global.asax running per app or one for each...
2
by: DamienS | last post by:
Hi, I'm trying to get away from using global.asax for reasons of 'neatness'. Am I able to register a HTTPModule that captures the starting of a user session? Isn't Session_Start an event in...
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a web application vs2005 and it looks like a condition is causing session veriables to be lost. This does not seem to be happening too often. The web application allows uploading and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.