Storing data in ASP.NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Say for example a user of my website makes a selection on the site and I want to store that value for use on a later page what is the best way to do that?
My only method at the moment that I know would be to create a static class and static variables inside of that. But if more then one person was using the page would they be using the same variables? Or do they get a version of the static class each?
I dont know, which is why I ask.

jax
 
Jax,

You are right, if the class was static, then the whole application would
have access to those variables. The best way to store data is to use the
HttpSessionState type, which is exposed through the Page class through the
Session property. Also, it is exposed through the HttpContext class,
through the Session property on that class. The type has an indexer which
is a hashtable. You can place whatever keys/values you wish in there
(depending on how you are storing the values, if they are persisted to an
ASP session server, SQL server, or in memory).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jax said:
Say for example a user of my website makes a selection on the site and I
want to store that value for use on a later page what is the best way to do
that?
My only method at the moment that I know would be to create a static class
and static variables inside of that. But if more then one person was using
the page would they be using the same variables? Or do they get a version of
the static class each?
 
Nicholas,

Thanks once more for the help, I think i'll use the Session.Keys collection to store the data. Sounds good.

Jax
 
Back
Top