简体   繁体   English

ASP.NET中的应用程序对象

[英]Application object in ASP.NET

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. 我正在阅读一篇文章,其中写道:“当用户第一次请求驻留在应用程序目录中的页面时,ASP.NET将初始化该应用程序。在此过程中,ASP.NET将创建一个应用程序对象,应用程序状态对象和一个缓存对象。

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']? 例如,迈克尔请求一个页面,然后设置Session [“ name'] =” Michael“,莎拉也请求一个页面并设置Session [” name'] =“ Sarah”,那么应用程序如何才能获得Session []的值? “名称']?

There is just one Application object per application, which is shared by all users. 每个应用程序只有一个Application对象,该对象由所有用户共享。 The Session object is not shared between sessions (and thus users). Session对象(因此没有用户)之间不共享Session对象。

The Session state is not part of the Application context. Session状态不是Application上下文的一部分。 ASP.NET knows which session belongs to who (based on session cookies for example). ASP.NET知道哪个会话属于谁(例如,基于会话cookie)。

For Sessions, see How the session work in asp.net? 对于会话,请参阅asp.net中的会话如何工作? . In short - it identifies the session via a cookie. 简而言之-它通过cookie标识会话。

For Application / Application State, there is one object. 对于应用程序/应用程序状态,只有一个对象。 See https://msdn.microsoft.com/en-us/library/ms178594.aspx for more details. 有关更多详细信息,请参见https://msdn.microsoft.com/en-us/library/ms178594.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM