共用方式為


Page and Application Context in ASP.NET Web Applications

When a Web application runs, ASP.NET maintains information about the current application, each user session, the current HTTP request, the requested page, and so on. ASP.NET contains a series of classes to encapsulate this context information.

ASP.NET makes instances of these classes available as intrinsic objects that you can access from your code. The following table lists these intrinsic objects and the classes they are instances of.

Object Name

Description

ASP.NET Class

Response

Provides access to the output stream for the current page. You can use this class to inject text into the page, to write cookies, and more. For details, see Page.Response property.

HttpResponse

Request

Provides access to the current page request, including the request headers, cookies, client certificate, query string, and so on. You can use this class to read what the browser has sent. For details, see Page.Request property.

HttpRequest

Context

Provides access to the entire current context (including the request object). You can use this class to share information between pages. For details, see Page.Context property.

HttpContext

Server

Exposes utility methods that you can use to transfer control between pages, get information about the most recent error, encode and decode HTML text, and more. For details, see Page.Server property.

HttpServerUtility

Application

Provides access to application-wide methods and events for all sessions. Also provides access to an application-wide cache you can use to store information. For details, see ASP.NET Application State Overview.

HttpApplicationState

Session

Provides information to the current user session. Also provides access to a session-wide cache you can use to store information, along with the means to control how the session is managed. For details, see ASP.NET Session State Overview.

HttpSessionState

Trace

Provides a way to display both system and custom trace diagnostic messages in the HTTP page output. For details, see ASP.NET Tracing Overview.

TraceContext

The following topics show examples of how the intrinsic objects can be used.

Object

Example topics

Application

Request

Server

Session

See Also

Concepts

Introduction to Programming ASP.NET Web Forms Pages

ASP.NET State Management Overview