Asp – Static variables in ASP.NET

asp.net

There is an article that recommends to store ASP.NET application state in static members of HttpApplication class (in Global.asax.cs).

What about storing application state in static members of other classes?

I tried to do so and it seems that there are several instances of these variables can exist (single instance per AppDomain?). Is it true and should we always use only Application class's static fields? Or it doesn't matter?

Best Answer

It works pretty well and it's better than Application in many cases (it's strongly typed, for instance). Just make sure you are aware of threading and locking issues.

As a personal experience, I've managed to cache configuration information for ASP.NET app in a static class in a couple Web sites.