Static variables in web requests
asp.net-mvc-3, c#, static-members
Solution
To answer your question in its simplest form; yes. Anything that's static will persist:
- Between requests
- Across all users
They won't be shared between different instances of the same application (e.g. in a load balanced scenario) and they will lose their values when the application pool recycles.
Generally speaking, it's a bad idea to try and persist state using static variables unless you have a very specific reason to do so.
If you are considering using static variables to save user-specific data between requests, don't. Because they are shared across threads (and therefore across both requests and users), you will introduce race conditions as soon as you have more than one user.
Opt for another form of storage, such as session state, cookies or - better still - a database.
Problem
How a static public variable in a static public class behaves between web requests in a C# MVC3 web project. Those types of variables mantain there values between requests or not?