RohannG
RohannG

Reputation: 669

What happened to application and session variables when one MVC web application hosted on a server accessed by multiple users at the same time?

We can define application and session variables in ASP.NET MVC. If I have a web application hosted in server then in multi user environment how application and Session variables be treated with respect to every user who uses that website at the same time. Means application variable will start every time when request coming from multiple users? I just want to know what will happened to application and session variables in ASP.NET mvc in details.

Upvotes: 0

Views: 1287

Answers (2)

Sudipta Kumar Maiti
Sudipta Kumar Maiti

Reputation: 1709

Session variables:

  1. Session variables are available and accessible in entire application for a particular user.
  2. These variables are available and stored on web server.
  3. Variables are destroyed once user session times out, default timeout is 20 minutes but it’s configurable in web.config. Session variables are also destroyed once user logs off (through session abandon).

Application variables:

  1. Application variables are available and accessible across application and across all sessions (multi-user global data).
  2. These are also available and stored in web server.
  3. Variables are destroyed once the hosting process restarts through restart of an application pool/ IIS reset etc.

Upvotes: 0

Bardo
Bardo

Reputation: 2523

Session variables have an associated value for each different session on the server. This means that when a session dies, their variable values dissapear and reset when the user came again to a new session.

Application variables, on the other side, are common to all sessions in the server. It must be used responsibly, as modifying it's values affect the whole application globally.

When application is restarted on IIS (when you update your project, for example), session and application variables are restarted.

Upvotes: 3

Related Questions