Sessions in C#

  • Thread starter Thread starter Will
  • Start date Start date
W

Will

ok.. I've created a namespace and a class in an assembly
file and included into my .aspx page as a custom control.
On that aspx page I store a string in a session as follows:

Session["strColor"] = "blue";

Now, inside my assembly file I want to retrieve that
variable. I have tried everything.. I have an instance of
the current session state as follows:

HttpSessionState mySession = ((HttpSessionState)
HttpContext.Current.Session);

now when I try to do something like:

private string strTemp = mySession["strColor"].ToString();

I get the follwing error:

A field initializer cannot reference the nostatic field,
method, or property 'myNamespace.myClass.mySession'

What does this error mean? And how can I retrieve
strColor? I have seriously tried a thousand things..
please be specific in your answers, thanks A LOT in
advance.

Will
 
Declare the field without initializing it, and in the Constructor method for
the class, assign it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.
 
Back
Top