Question about .net static objects

Are the values ​​of the static variables the same for one session, or are their values ​​the same at the application server level?

+4
source share
3 answers

They are at the AppDomain level - the same for all static variables, regardless of whether they are in ASP.NET or not.

So:

  • If you use the same class from different AppDomains, you will get separate variables
  • If your AppDomain is redesigned, you will get separate variables
  • If two requests go to different machines, you will get separate variables
  • If two simultaneous requests fall into the same AppDomain, they can interact with each other (therefore things like count++ are not safe)
+11
source

I think as long as the iis process exists, the static variable will hold its value

0
source

The variable will remain in memory until the application restarts.

0
source

All Articles