Loosing session state when I call a session variable from a derivated class

Hi folks

 I'm having an annoying problem. I have a web application which is used to edit some database data. The databases content may be in various languages, having one database for each language. I load a database calling it by the database name and the language suffix (for example: database_eng, when 'eng' is the laguage variable).

 
So, I need to set a session variable 'Language', which is used in any webpage that calls information from a database. The problem I have is in some classes, which stores some methods to obtain information from databases. These classes have a 'Base' parent class, and some derived class, which inherits 'Base'. Likewise, the 'Base' class inherits from System.Web.UI.Page.

 
Then, I set a session variable 'language' in Global.asax file, which initially stores the default language code. Index.aspx shows right, but when I try to change to other page (which inherits from a 'DerivedBaseClass' class, i'm having error message described below:


"Exception details: System.Web.HttpException: Only the session state can be used when enableSessionState is set as true, in a configuration file or in a page directive."

 
Of course I have enableSessionState as true. In fact, If i try to call the 'Language' session variable from the 'Base' class constructor method, and I try to create a new 'Base' instance from the index.aspx, and then, call the 'Base' variable which contains 'Language' string, runs perfectly:

 Example:

public class Base : System.Web.UI.Page
{
           string Language;

            public Base()
            {
                this.Language = Session["Language"];
            }

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

(index.aspx)

private void Page_Load(object sender, System.EventArgs e)
{
    Base objLanguage = new Base();
    string TryCallLanguageSessionVariable = objLanguaje.Language;
}

 
In the example TryCallLanguageSessionVariable load the session variable called from 'Base' class correctly. However when a page calls a 'Base' derived class, I'm having the exception I described before, in the same 'Base' class constructor method.

Also, I can't load the language variable in any cookie or querystring from the 'Base' class. It throws the follow exception in the same point where it throws using the session variable.

"Exception details: System.Web.HttpException: Request unavailable in this context"

Is there any problem calling session variables from a class, which inherits from a class2, which inherits as well from a class3, which inherits from 'Base', which also inherits from System.Web.UI.Page? (but is not an aspx web page).

 
Thanks in advance.
 


 

0
Borjaserrano
7/9/2007 9:55:37 AM
asp.net.state-management 8807 articles. 0 followers. Follow

2 Replies
1243 Views

Similar Articles

[PageSpeed] 27

The problem is that you're trying to read the session state from the constructor of your class, which is too early in the page lifecycle for it to be accessible. Try overriding the OnInit method for instance istead:

public class Base : System.Web.UI.Page
{
           string Language;

            protected override void OnInit(EventArgs e)
            {
                this.Language = Session["Language"] as String;

                base.OnInit(e);
            }

}

 


Blog: http://iridescence.no
0
Fredrik
7/9/2007 12:19:28 PM

 Thank you very much mate!, problem resolved!! Smile

0
Borjaserrano
7/10/2007 8:04:46 AM
Reply:

Similar Artilces:

Session variables vs. Session States
What is the difference and in what situations are they used. Thanks, Mattypee A session state (the state of your session) holds your session variables. If your session state expires (due to inactivity) then you lose your session variables...and any other info stored for that session. If you need to store USER specific information within a web app, then session variables are one(of several) ways to do it. MajorCatsMajorCats Is there any code that you could show that would give an example? Thanks, Mattypee example of what? reading and writing session variables? ...

Session state, app state or class?
    Greetings     I developing an application which will load a number of panels onto a page    The number of panels to display on the page will depend on data which was     stored in a sql db during setup phase    Which is the most effecient way to get that data?    1) run a class on the server which gets the data from the db and sends it to        the browser each time the page is displayed     2) run the class on the server on app start and then ...

The page requires session state that is no longer available. Either the session has expired, the client did not send a valid session cookie, or the session state history size is too small. Try increas
Hi.. I am making a mobile application using .net framework 2.0. My Application has  web farm scenario so for state management  I am using Sateserver in my application. My application runs fine if I dont use web farm scenario But in case of web farm scenario it is giving me error "The page requires session state that is no longer available. Either the session has expired, the client did not send a valid session cookie, or the session state history size is too small. Try increasing the history size or session expiry limit."   &...

"The page requires session state that is no longer available. Either the session has expired, the client did not send a valid session cookie, or the session state history size is too small. Try increa
Hi.. I am making a mobile application using .net framework 2.0. My Application has web farm scenario so for state management I am using Sateserver in my application. My application runs fine if I dont use web farm scenario But in case of web farm scenario it is giving me error "The page requires session state that is no longer available. Either the session has expired, the client did not send a valid session cookie, or the session state history size is too small. Try increasing the history size or session expiry limit." I am not getting why this error is coming ..Though I already h...

Session State Variables across multi sessions
I am having an issue where I save my DataTable into a Session Variable:   Session["dtDMFile"] = dtDMFile; Different users can use the web form that I created. Once the data is loaded,I send the DataTable to the session variable. My problem is that when I go to reload the data in the table, it is taking the data from the last user who stored the DataTable instead of from the particular user on their browser. For instance, User 1 (machine 1) loads data with field contents of: field1  field2  field3 User 2 (machine 2), then loads data with field contents of: f...

Unable to make the session state request to the session state server.
 Hello,           I’m receiving this error when I put my website on production."Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same.  If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection.  If the server is on the local machine, and if the before men...

Unable to make the session state request to the session state server
Hi all, I'm working on the website http://universityauction.net and I was using session variables using InProc session mode to manage session state. This worked fine until I put the website in a load balanced environment, as inproc sessions get lost when jumping from server to server. I decided to move to a state server mode, so I changed my web.config to: <sessionState             mode="StateServer"             stateConnectionString="tcpip=123.456.7.8:42424"      ...

Error: Unable to make the session state request to the session state server
I have session configured in web.config this way:<sessionState mode="StateServer" cookieless="true", timeout="30" stateConnectionString="tcpip=127.0.0.1:42424" />  ASP.NET State Service is started.   I got an error:  Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same.  If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentContr...

Unable to make the session state request to the session state server etc.
We are getting an error message "Unable to make the session state request to the session state server..." sporadically in one of our applications.  We have several applications running on a 4-server web farm, and these applications have been in production for a year, so it is not a problem that the server is not reachable, not started, not addressed correctly, etc etc etc. One of the applications *does* put a lot of large datasets into session state.  Is there a limit on the allowable size of a session/cached object?  Also, the application opens several windows at once, ...

Unable to make the session state request to the session state server #2
We have recently started receiving these errors in the event viewer. We are using the out of proc state server on the same machine. The errors become more frequent, almost like it snowballs until users cannot work. System Info: Windows Server 2003 Standard SP2 , 4 GB of RAM, IIS 6.0, Asp.Net 2.0. What I know for certain: The state server is started and running Recycling the app pool nor restarting IIS fixes the problem Rebooting the machine DOES temporarily fix the problem. I changed the stateNetworkTimeout from 10 to 20 in webconfig and that had no effect. There is usuall...

Session state variable in class library
Hi guys,  How can I get hold of a session state variable in a class library (middle-tier), that is referenced by my web app? ThanksThe best glimpse of heaven is on the way into hell ;)yousef.omar@gmail.comhttp://nonstopbiztalk.blogspot.com You can get the current context to use it into the library HttpApplication.Context.Current.SessionCheersAlMy BlogMapStats.NETPlease click on 'Mark as Answer' if this post answered your question! First you will need to add a reference to the System.Web assembly. Once you've done that, you can access Session using: System.Web.HttpCon...

Unable to make the session state request to the session state server
 We have a web application in our school called CHECM. We are experiencing a high volume of ASP.NET State Server errors throughout this month. These errors have been occurring since 7/11/2006.   Our Session State Mode has been --------------------------------------------------------- <sessionState mode="StateServer" stateConnectionString="tcpip=CHECM:42424" timeout="20" stateNetworkTimeout="30"/>     Here is the Error we get randomly Exception: System.Web.HttpException Message: Unable to make the session state request to the session state server. P...

Visual Studio 2005
 Hi, I have recently been given a PC with Vista on it, and installed Visual Studio 2005 pro. I then moved a ASP.net web project from an XP machine to the Vista one. When I run the project from inside Visual Studio (debug mode) everything works fine on the front end of the website, but if I try and log in I get the following error:  Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same.  If the server is on a remote machine, please ensure that i...

State management upon session variable changes
I noticed that whenever a session variable is changed...the application knows about it and suddenly restarts session. My question is does restart "ALL" sessions or only the active sessions for which the variables changed? Imagine a "multi-user" application all with different states and an administration panel that lets you change session variables.  In this case, my question has to do with the question that if Company X changes his session variables, will only Company X's sessions be reset or will all "sessions" be reset?  Hope that makes sense. ...

Web resources about - Loosing session state when I call a session variable from a derivated class - asp.net.state-management

Besançon - Wikipedia, the free encyclopedia
French Land Register data, which excludes lakes, ponds, glaciers > 1 km² (0.386 sq mi or 247 acres) and river estuaries. Coordinates : 47°14′35″N ...

Wikipedia:WikiProject Maps/Conventions - Wikipedia, the free encyclopedia
Here is displayed the summary table of each major map convention used across the wikipedias. Each convention has its own subpage, which should ...

DCA-FEEC-UNICAMP DCA Overview
The Department of Computer Engineering and Industrial Automation was established when, in 1971, the former Department of Automation of the then ...

Eating Out in Belgrade - Belgrade Restaurants - Restaurants in Belgrade
Belgrade offer plenty of restaurants specialising in every cuisine your pallet desires. Find out where you can eat in Belgrade, whether you prefer ...

The press, Google, its algorithm, their scale
... traffic : comply or ignore? Each and every media gathering those days includes one subject: how to deal with the increasing traffic derivated ...

Opiate
Opiates are any of the narcotic found in the opium poppy plant, as well as any other drugs that are derivated from it.

MARC FORNES & THEVERYMANY™ - ART + ARCHITECTURE ^ COMPUTATION [ Python / Rhinocommon SDK ]
2014 - Vaulted Willow - Permanent Public Art Pavilion - Borden Park, Edmonton, Canada Commissioned by The Edmonton Arts Council and completed ...

Products, Trade Leads, B2B Products, Global Directory Online
International products & trade leads directory Toboc offers quality product leads through online global B2B marketplace. Find latest products ...

Ben’s Lost World – Diary of a GeeXboX developer
Good news everyone ! I recently ‘ve been sponsored Nokia N900 phone by CELF, this awesome pro-Linux foundation that already used to sponsor me ...

Tea with FT: Enron
Sir Dr Len Rosenthal in his letter “Ratings need to learn lessons from Enron”, June 27, gives many good recommendations for how the rating agencies ...

Resources last updated: 11/27/2015 10:47:32 AM