I want to define a variable or object like session, to stored data about each user, and i want to access this object in many pages, could u please tell me if there is a way. thanks
4 Answers
You can store data in a cookie and then in your codebehind parse the specific cookie into something like a System.Collections.Generic.Dictionary
But you should use sessions.
Edit
IF if's a KeyValuePair<String,TValue> you can set Session[kvp.Key] = kvp.Value;, if not Session["KVP"] = kvp;
2 Comments
i've had a few situations where I wanted to minimize/eliminate session storage (due to users being on a horrible wifi connection). to handle this situation I used an encrypted query string with only their ID in the string. in the base page I would decrypt the string and pull information I needed from the database. This information would be populated into objects that I defined and since the objects were in the base page I could access the information from any pages that inherited it.
Sessionvariable.Session["X"] = your_KeyValuePair_variableorSession["Your_Helper"] = new your_helper_class()will also work - at least for In-Proc session mode. Are you using some other session mode?