What is the difference, in practice, between Session and Application?


I'm studying about Web Technologies , and during my class a topic about concepts involving Session and Application came up. The technology covered during class was C# . I did not quite understand the differences between them. Searching, I found the following answer:


The main difference between these two concepts is that the state of    session stores variables and objects for a particular user, and   exists while the user session exists while the status of the    application stores variables and objects that are shared with   all users of the application at the same time.

Source: ASP.NET 2.0 - Presenting with the Application object

However, I did not see the applicability of these concepts in practice. Could anyone elucidate situations where I can apply each of them? These concepts apply to other types of technology, such as Java , PHP , Javascript ?

asked by anonymous 27.11.2015 / 16:35

2 answers


You've answered half the question already. Session is a scope of settings for a given user. Application is a scope of settings for the entire application.

Speaking of C #, the application log usually stays in a source called Global.asax.cs . It does the global registration of classes, components used and primary mapping of aspects. Recently, Microsoft has changed some approach, using partial classes with the name Startup , but the principle is the same.

In Java the application and session architecture is not consensual. Each vendor packages and distributes the architecture in a way. Although similar, they are not exactly compatible. The design pattern of an application for WebSphere is different from the standard of a project for JBoss, for example, and usually porting from one to another requires a large amount of configuration and customization.


I could not visualize the applicability of these concepts in practice. Can anyone clarify situations where I can apply each of them?

When authenticating a user and loading their permissions, you use session scope.

When you load routes, environment settings, and objects used by the application as database abstraction objects (which require preconfiguration), you are using application scope.


Do these concepts apply to other types of technology, such as Java, PHP, Javascript?


27.11.2015 / 16:56

Session is each user logged into a web application. Session data is useful when it is individual to the user. For example, every user logged in here in the forum has his Session.

A shopping cart in a web store is stored as Session data because it is individual to the user that is accessing. When the browser / tab is closed, or I log off that data is lost.

Application is the web application as a whole. Application data is the same for everyone. In a web chat for example the data is stored in the application. All logged in users come with the same content.

Even if one or more users log off or close their browsers, the data will be available to everyone who is still accessing. The data is only lost when the application server is shut down or someone deletes that data.

About using in other languages, yes is possible. Any web programming language apply these concepts.

Obs : These concepts above should not be confused with data persistence. We are talking about data in memory (server RAM).

Nothing prevents data from being stored in a database for later reference.

27.11.2015 / 17:28