1

I was reading a article saying " the first time a user request a page that resides in an application's directory, ASP.NET initializes the application. During that process, ASP.NET creates an application object, application state object and a cache object.

My questions are:

  1. Let's say I have many users request a page from the application, how many application state objects are created by the application? just one or many? will new application state object be created for every new user? or all users share the same objects?

  2. If there is only one application object created, how can the application know which Session belongs to which users? For examples, Michael requests a page, nd setting Session["name']= "Michael", Sarah also requests a page and setting Session["name']= "Sarah", so how can the application what's the value of Session["name']?

2 Answers2

1

There is just one Application object per application, which is shared by all users. The Session object is not shared between sessions (and thus users).

The Session state is not part of the Application context. ASP.NET knows which session belongs to who (based on session cookies for example).

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
0

For Sessions, see How the session work in asp.net? . In short - it identifies the session via a cookie.

For Application / Application State, there is one object. See https://msdn.microsoft.com/en-us/library/ms178594.aspx for more details.

mjwills
  • 23,389
  • 6
  • 40
  • 63