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

Asked

Viewed 883 times

15

I’m studying about Tecnologias Web, and during my class there was a topic about concepts involving Session and Application. The technology addressed during the class was C#. I didn’t quite understand the differences between them. Searching, I found the following answer:

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

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

However, I could not visualize 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?

2 answers

11


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

Speaking of C#, usually the application record is in a source called Global.asax.cs. It makes the global record of classes, components used and primary mapping of aspects. Recently, Microsoft switched a bit of approach, using partial classes with the name of 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 one way. Although they look alike, they’re not exactly compatible. The design pattern of an application for Websphere is different from the standard of a project for Jboss, for example, and normally porting from one to the other demands a large amount of configuration and adjustments.

I could not visualize the applicability of these concepts in practice. Someone could elucidate situations where I can apply each of them?

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

By loading routes, environment settings and objects used by the application, such as database abstraction objects (which require prior configuration), you are using application scope.

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

Yes.

  • 3

    Just to complement, in . NET environment, among these there is the Cache, which also has application scope. And it is recommended not to use more Session, see more details on this website.

  • 3

    @Thiagolunardi Corretíssimo. Since 2010 giving problem Load Balancing.

8

Session is each user connected to 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 their Session.

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

Applying is the web application as a whole. The application data is the same for everyone. In a web chat for example the data is stored in the application. All logged in users see the same content.

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


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


Obs.: These above concepts 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.

  • 1

    Shura16, session data is not in the client’s RAM. They also stay on the server, the difference is that only the respective session has access.

  • In some cases yes, so I quoted server/client.

  • 1

    Shura16, the fact remains that your statement about the Session being stored in the client’s RAM is incorrect. WEB applications maintain status in various layers, however when it comes to Application and Session we are talking about server. The status of a shopping cart, for example, stays on the server, what stays on the client are cookies (including the session ID) and the state of the browser itself with the AJAX calls, for example, but this is not session according to the context of the question. If Session were in the customer’s RAM, there would be several security issues.

  • Corrected on the issue of memory.

  • Won a +1 my.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.