I am using session objects in C# ASP.net.
I like to know whether I can declare and use an array of such objects.
For example assume there is a session object “User”, then I say:
User[,] u_sers_ = User[3,4].GetCurrentUser;
What I am trying to do is declare an array of session objects, is this possible?
If it is not possible, how do I declare an array of object “members”?
Thanks
Nothing in your code above involves any
Sessionobject. You may have some terminology confusion, here:The object named
Sessionis a member variable of thePageinstance object, among others. It is there as a convenience to refer to the session object for the current user session. You do not do anything to create an ‘array’ of these objects – there is only one per-user-session currently active, and eachPageand other similar object can only deal with the current one.You put objects in the Session dictionary to use them. Again; this is a single object, automatically created and scoped per-session for you. You do not create it. But you do create individual objects to insert into the
Sessionobject, and it stores them for you, keeping track of whichSessioncollection is attached to which session.You could certainly put an array of something in the
Sessiondictionary, but I don’t think that’s really what you are looking for here.Edit Session usage:
In one page, you can add things to your
Sessionobject:Then you can refer to those object by their name, after testing to make sure they really do exist and casting them properly. You always must test that the object exists, because the Session could expire at any time.