How do static properties work in an asp.net environment? How do static properties work in an asp.net environment? asp.net asp.net

How do static properties work in an asp.net environment?


Statics are unique to the application domain, all users of that application domain will share the same value for each static property. When you see the word static, think "there will only be one instance of this." How long that instance lasts is a separate question, but the short answer is that it is variable.

If you want to store values specific to the user look into Session State.


In addition to Bob's answer, there is this exception of course:

public static object Item {    get { return HttpContext.Current.Session["some_key"]; }}


Static fields and properties are shared across all instances of a class. All of your users will end up sharing the same value.

The value will be there until the ASP.NET worker process recycles itself (which happens periodically).