2

I am developing a Web Application that allows multiple user access on it.

And in the code behind I am using a property in which i am saving some personal details of the user.

My question is, if I made those properties as static will be there any conflict in data saving in the property when multiple user doing the same thing.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
NCA
  • 810
  • 1
  • 8
  • 19
  • 2
    _" a Web Application"_ with ASP.NET? If so, of course there will be conflicts since every user/request is a different thread that tries to access the static field. Don't do it if you don't have to. – Tim Schmelter Nov 06 '13 at 08:17
  • Why would you want to make them static, when in fact they are not? – germi Nov 06 '13 at 08:18
  • 1
    Check this question : http://stackoverflow.com/questions/14154892/scope-of-static-variable-in-multi-user-asp-net-web-application Maybe this can help you. – Bart Schelkens Nov 06 '13 at 08:20
  • possible duplicate of [static variable ASP.NET](http://stackoverflow.com/questions/16303655/static-variable-asp-net) – Tim Schmelter Nov 06 '13 at 08:27

3 Answers3

7

Do not do that. Static values are shared between user sessions so you would override those values for each different user.

Use Session or Cookies to store data for specific user.

gzaxx
  • 17,312
  • 2
  • 36
  • 54
  • 2
    There are other options (like `Cache`(app-scope) or `ViewState`(page+user-scope)): [Nine options for managing persistent user state in your ASP.NET application](http://msdn.microsoft.com/en-us/magazine/cc300437.aspx) – Tim Schmelter Nov 06 '13 at 08:24
2

There will be issues if multiple people are using simultaneously and if he app is deployed.

Mrinal Saurabh
  • 948
  • 11
  • 16
0

static memebers are maintained only one copy which is common for all the users who see it, hence it's not good to use when you wnat to maintain it for multiple users.

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67