1

I'm old to VB but new to ASP.NET

I have written several dictionaries in new website. problem is that if multiple users are using these dictionaries at the same time, one user gets another user's information.

Being new to ASP.NET, what would the best way to get around this problem be? Session State or ViewState? Am I looking in teh wrong direction?

  • 1
    _"if multiple users are using these dictionaries at the same time, one user gets another user's information"_ only if they are static/shared or you used the `Cache`. – Tim Schmelter Jul 11 '12 at 19:36
  • possible duplicate of [What is the difference between SessionState and ViewState?](http://stackoverflow.com/questions/733482/what-is-the-difference-between-sessionstate-and-viewstate) – Tim Schmelter Jul 11 '12 at 19:37
  • Being new to ASP.NET, the best advice I ever received was "use static only if you REALLY mean it." Many WinForms/desktop developers liberally use static variables to maintain state, but end up running into a lot of trouble with that paradigm when they make the switch to web development. – Jaime Torres Jul 11 '12 at 20:06

3 Answers3

2

Server Side:

Session is a user specific or you can say browser specific. It is not shared among all the users of a site. Session can hold any object data type.

Session["key"] = "value";

Application is shared across all the users on the site.

Application["key"] = "value";

Client Side:

ViewState data is not shared among users and even not among the pages. It retains the data during a post back.

ViewState["key"] = "value";
Waqar Janjua
  • 6,113
  • 2
  • 26
  • 36
1

Session will hold information that is particular to a user and last for the user's browsing session. ViewState will hold the information that is particular to the controls on the page that the user is currently browsing.

If you would like to store information that is specific to a user and needs to remain with them as they browse the site, Session is a fine solution for that.

Trey Combs
  • 710
  • 5
  • 10
0

if you want to access data like User information such as Name,LastName,... Session is best choice bacause this data not change for current user. but if you want to store a value in a variable you should consider concurrency problem.for example if you have a page with a simple button and text box that after clicks on button text box value stored in Session ,if user open 2 instance of that page then there will be a session conflict.every button clicks over write session data. if you want store variable in a page you can use ViewState but you should consider this value can see easily by user.and if you want to secure values you should use View State Encryption. and if you want pass values between pages you can use Query String

Good Luck

Arian
  • 12,793
  • 66
  • 176
  • 300