Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. What exactly Difference between Application and Session ?

What exactly Difference between Application and Session ?

Scheduled Pinned Locked Moved ASP.NET
questioncareer
6 Posts 4 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    satyamzen
    wrote on last edited by
    #1

    Hi all, While i went to an interview interviewer asked me Difference between Application and Session ? Application common for all users but session is user level, but he didn't convinced with my answer. Please explore on my question. Thanks..

    D A D 3 Replies Last reply
    0
    • S satyamzen

      Hi all, While i went to an interview interviewer asked me Difference between Application and Session ? Application common for all users but session is user level, but he didn't convinced with my answer. Please explore on my question. Thanks..

      D Offline
      D Offline
      Dennis Dykstra
      wrote on last edited by
      #2

      According to Wikipedia[^], "a web application is an application that is accessed via a web browser over a network such as the Internet or an intranet. The term may also mean a computer software application that is hosted in a browser-controlled environment (e.g. a Java applet) or coded in a browser-supported language (such as JavaScript, possibly combined with a browser-rendered markup language like HTML) and reliant on a common web browser to render the application executable." By comparison, a browser session starts when an individual user accesses or logs onto a particular website and concludes when the user logs off, closes the browser, or clicks away from that website. The session may or may not involve authentication.

      1 Reply Last reply
      0
      • S satyamzen

        Hi all, While i went to an interview interviewer asked me Difference between Application and Session ? Application common for all users but session is user level, but he didn't convinced with my answer. Please explore on my question. Thanks..

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        satyamzen wrote:

        While i went to an interview interviewer asked me Difference between Application and Session ?

        I guess he has asked about "Application State" Not "Application" . You can explain them in following way. System.Web.HttpApplicationState class is used to maintain the Application State For ASP.NET Application.It provides methods for storing information which can be accessed globally means it common for the all used. As For Example : Storing Info At Application Variable :

        Application["Title"] = "Welcome";

        // Reading the Information from application variable

        string Title;
        if (Application["Title"] != null)
        Title = Application["Title"].ToString();

        On the other hand Session stored on server side and its unique for each and every user. We can interact with Session State with System.Web.SessionState.HttpSessionState class, because this provides built in Session Object with Asp.Net Pages. As For Example : Following code is used for storing a value to session

          //Storing UserName in Session
           Session\["UserName"\] = txtUser.Text;
        

        Now, let see how we can retrieve values from Session

        //Check weather session variable null or not
        if (Session["UserName"] != null)
        {
        //Retrieving UserName from Session
        lblWelcome.Text = "Welcome : " + Session["UserName"].ToString();
        }
        else
        {
        //Do Something else
        }

        Below are the associated events that are used for Session and Application State. This are events for Global.asax file. For Application : Application_Start, Application_End For Session : Session_Start and Session_End

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

        1 Reply Last reply
        0
        • S satyamzen

          Hi all, While i went to an interview interviewer asked me Difference between Application and Session ? Application common for all users but session is user level, but he didn't convinced with my answer. Please explore on my question. Thanks..

          D Offline
          D Offline
          Dinesh Mani
          wrote on last edited by
          #4

          The simplest answer to that question would be that an Application or variables in Application state are initialized when the application receives the first user request. Data in the application state is common to all users. Application variables generally get recycled during Application Pool recycling [This is my understanding, somebody please confirm!!]. Session on the other hand is user specific and starts when the server receives the first request from a user browser and ends after the user closes the browser. Each user gets a separate share of memory for his session data and hence Session variables have to be used cautiously. Also, one user can open more than one session from the same computer using different browsers, i.e. I can get two session to CP and login using 2 different logins, from IE and Firefox, simultaneously. HTH!!

          A 1 Reply Last reply
          0
          • D Dinesh Mani

            The simplest answer to that question would be that an Application or variables in Application state are initialized when the application receives the first user request. Data in the application state is common to all users. Application variables generally get recycled during Application Pool recycling [This is my understanding, somebody please confirm!!]. Session on the other hand is user specific and starts when the server receives the first request from a user browser and ends after the user closes the browser. Each user gets a separate share of memory for his session data and hence Session variables have to be used cautiously. Also, one user can open more than one session from the same computer using different browsers, i.e. I can get two session to CP and login using 2 different logins, from IE and Firefox, simultaneously. HTH!!

            A Offline
            A Offline
            Abhijit Jana
            wrote on last edited by
            #5

            Dinesh Mani wrote:

            ends after the user closes the browser

            No, session does not end when user closed the browser. Session stored in Server Side. So If you are using Inproc session Session will automatically end when it reached the Session Timeout . So, If user close the browser, session will not end that time. Some of application may trap the Browser close and close the session from server end too. :) Thanks !

            Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

            D 1 Reply Last reply
            0
            • A Abhijit Jana

              Dinesh Mani wrote:

              ends after the user closes the browser

              No, session does not end when user closed the browser. Session stored in Server Side. So If you are using Inproc session Session will automatically end when it reached the Session Timeout . So, If user close the browser, session will not end that time. Some of application may trap the Browser close and close the session from server end too. :) Thanks !

              Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

              D Offline
              D Offline
              Dinesh Mani
              wrote on last edited by
              #6

              I meant from a generic user perspective! That's why I had mentioned as "after the user closes the browser" and not as "when the user closes his browser". Since the Session expiration policy is different for different session policy I didn't want to get into the details! Anyway I guess I should have been very particular and specific! :)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups