0

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

8
  • 2
    why wouldn't you use Session ? Commented Mar 16, 2012 at 11:55
  • What you want to use is a Session variable. Commented Mar 16, 2012 at 11:56
  • because i want to store keyValuePair, Commented Mar 16, 2012 at 11:57
  • and i want to use an object to provide its class with some usefull methodes to help me later Commented Mar 16, 2012 at 11:58
  • 1
    @Sum: Session["X"] = your_KeyValuePair_variable or Session["Your_Helper"] = new your_helper_class() will also work - at least for In-Proc session mode. Are you using some other session mode? Commented Mar 16, 2012 at 11:59

4 Answers 4

1

You have onlyy a few choices, really. URL parameters, hidden form inputs, cookies, session (be careful in a load-balanced scenario) or just store/retrieve stuff from a database. RaveDB is bloomin' brilliant for this because it's so fast and document-based.

Sign up to request clarification or add additional context in comments.

Comments

0

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

None that I know of, simply because you usually don't need this. There is a finished solution, why build another one.
I think session is probably what you need. Just be aware that there can be issues if you start persisting session state (for example in a load-balanced scenario).
0

If u really don't want to use session use Database mind that this is a slow method...

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.