Reputation: 93
I'm using global variables in my web application. The web application does have a log-in and can allow multiple users. The global variables are used to store data for the items currently being processed.
Will my application be in chaos if multiple users tried to access these global variables or will it be just global in their respective workstation?
If it will create chaos, what's the best way to replace the global variables.
Upvotes: 2
Views: 3857
Reputation: 157136
Don't use static
variables in your ASP.NET application! They are shared across all sessions / users since they are kept in the web server, not on clients!
You have a few options, built-in already in ASP.NET:
You can easily create a property in a class that uses one of those (of course you could do this without properties, but I think they are a better practice):
public List<string> SomeSettingPerUser
{
get
{
return (List<string>)HttpContext.Current.Session["SomeSetting"];
}
set
{
HttpContext.Current.Session["SomeSetting"] = value;
}
}
Upvotes: 2