Class Visibility Question

  • Thread starter Thread starter BG
  • Start date Start date
B

BG

Hey All,

I have a simple understanding of session variables. Can the same thing be
done with a class in ASP.net?

Such as default.aspx contains a new instance of MYClass. So I load
MyClass.MyName = "Fred". Now ,umpteen response.redirects later, umpteen
pages later deep within the web site, I want to display MyClass.MyName and
it will still contain "Fred".

Possible?

Thanks,

BG
 
One ot the ways to achieve this is to store the object in the Session
and later retrieve it:

Session["MyClass"] = MyClass

The object is stored in the Session object until it is explicitly
removed, the session times out or is emptied in some other way. You
retirieve it when you like with guarantee that it is not changed unless
you have changed it yourself:
MYClass MyClass = (MYClass)Session["MyClass"];
 
You can map a property to a session

class X
{
public strinf NAme
{
get
{
return (string)Session["Name"];
}
set
{
Session["Name"] = value;
}
}
}
 
Back
Top