Can multiple users share an HttpApplication instance?

1.8k views Asked by At

I've used the table at the top of this article as a reference. I have three questions:

1 - Can multiple users (from different physical locations) ever share an HttpApplication instance? If so, does this happen by default?

2 - Can multiple users (from different physical locations) ever share an HttpApplicationState instance? If so, does this happen by default?

3 - Can multiple users of an ASP.NET application ever share a singleton instance or a static variable value? If so, does this happen by default?

Thanks for clearing this up.

2

There are 2 answers

2
SLaks On BEST ANSWER

The answer to all six of your question is yes.

Per-user state should be stored in the Session.

8
Jeff Fritz On

The HttpApplication contains the state of the Asp.Net application on a per w3svc.exe instance. So, per web server in your application, the application state is stored. If you are using web gardening, there are other concerns with the HttpApplication object.

All users on the same server, on the same thread will share HttpApplication, HttpApplicationState, and all static variable values. When multiple HttpApplication instances are running on a server, concurrent users will not be accessing the same instance of these objects. I do NOT recommend storing values in these objects... it is a much better practice to use the Cache object to store values you wish to share across users on a server.

Cache Object

The Cache object can take dependencies and expiration time values... this will allow you to control the 'freshness' of the values you are storing on a server.

Per user values should be stored in the Session object.

Session Object