Click to See Complete Forum and Search --> : Session objects


heavenly_blue
07-09-2004, 10:56 AM
I have things like this in the head of a page I have...


<%
Session("FirstName") = Request.Form("FirstName").Item;
Session("LastName") = Request.Form("LastName").Item;
%>


Is there a way to have just one session object, but multiple parts of it? I'm not sure what te correct terms are for it but I wanted to do something like...


<%
Session("UserInfo");
Session("UserInfo").FirstName = Request.Form("FirstName").Item;
Session("UserInfo").LastName = Request.Form("LastName").Item;
%>


Is there a way to do something like that? I don't want to have like 30 session variables, I just want one with all the info in it.

russell
07-09-2004, 12:04 PM
Not quite, but you can do this:

Session("UserName") = array("John", "Doe")
Response.Write session("UserName")(0) & " "
Response.Write session("UserName")(1)

Be warned that Session objects are strongly discouraged in a multi-server environment, as they defeat load balancing schemes.

buntine
07-09-2004, 11:31 PM
Agreed, storing an array in a Session object should solve your problem.

From memory, i thought there was some way of storing several data in the same Session object, much like you can in an ordinary Cookie.

Regards.

russell
07-10-2004, 06:12 PM
Hey buntine. I always look forward to your posts. In vbscript asp, you can do this for cookies (as you know)

Response.Cookies("myCookie")("myName") = "Russell"
Response.Cookies("myCookie")("myMonth") = "April"

But the same syntax doen't work with Session objects.

I'm thinking that you can create an object in memory and do what
heavenly_blue wanted originally, but off the top of my head it's not working. Thinking something like the JS prototype constructor... maybe an asp class would do the trick -- it would do the trick -- but why bother creating a class just to store session object values?! lol.