Would someone be kind enough to explain or point to article that explains how the scope of static classes and methods interact with the scope of a ASP.NET user session.
Here is the more specific situation which explains my question:
Is the data already initialized once user B hits it?
Also what if the asp.net session of user A expires before user B hits the website?
ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request.
We can not be use the Session object in static method so to its problem while reading the session value in static method ,to overcome this problem we need to read session value like as shown in following code snippet: HttpContext. Current. Session["UserName"].
Session is used to store data values across requests. Whether you store some data values with in the session or not Asp.Net MVC must manage the session state for all the controllers in your application that is time consuming.
Session is a feature in ASP.NET Core that enables us to save/store the user data. Session stores the data in the dictionary on the Server and SessionId is used as a key. The SessionId is stored on the client at cookie. The SessionId cookie is sent with every request.
Static data lives as long as the process is running. It is attached to the type.
If the data that is initialized is in a static context, then when user B hits the method, it will already be initialized.
Sessions are not relevant here - only the process.
If the process gets recycled, then the data will have to be reinitialized.
Check these posts: Why does my ASP.Net static function's "context" crossover between user sessions?
What is the scope of a Static Class?
C# Static variables - scope and persistence
http://msdn.microsoft.com/en-us/library/ms173138(v=vs.100).aspx
In short:
Is the data already initialized once user B hits it?
Yes
Also what if the asp.net session of user A expires before user B hits the website?
User B will access data initialized by user A
Static data is shared among the entire application domain of your webapp. It's shared among all the threads serving requests in your webapp, it's not bound to a session/thread/user in any way but to the webapp as a whole.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With