Re: Some basic session state questions



Hi,

My understanding is that session info must be stored using
Session["var"], which means text data. What I'd like to be able to do,
is keep an object alive throughout a user's session, without having to
serialize my data into text, save it as Session["var"], and restore it
using Session["var"] every time the user moves to a different page.

Is there no way to have a session *object* stay in memory and preserve
variable state without serialize/deserialize/Session[] ?


Thanks in advance

In Session you store *objects* (or rather: *references* to objects), not just strings. So you can store any object there without (de)serialization. That is, if you use "InProc" sessions. When you use StateServer or SqlServer to store session data, then the object needs to be serializable, but you don't have to do it yourself.
When you retrieve the object from Session, you have to cast is to the correct type.

MyObject obj = new MyObject();
Session["mine"] = obj;
....
MyObject obj2 = (MyObject)Session["mine"];


By the way, there is also a microsoft.public.dotnet.framework.aspnet newsgroup...


Hans Kesting


.



Relevant Pages

  • Re: Session expiration
    ... globally setting the session timeout ... to 60 minutes will cause higher resource consumption ... you will need 1GB RAM just to store session data. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Session expiration
    ... you can set the timeout ... session during normal working hours. ... > It's like trying to make a web app as close to client server as possible. ... >> you will need 1GB RAM just to store session data. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Session Variable Alternative
    ... You can use a StateServer to store session data in RAM on another box (or ... You can also persist the session to a database if you want. ... I use forms authentication and store the user name in the Identity object ... "Drew" wrote in message ...
    (microsoft.public.dotnet.framework.aspnet)
  • Persisting Application data/state
    ... Recently I've learned of the ability to store Session data outside the ... persistance. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: stale session files
    ... there is a garbage collector that will clear out old session files. ... Every time a session starts it is 1 percent chance that it ... and store session data in a database. ...
    (comp.lang.php)

Loading