Page.Session 属性

定义

获取 ASP.NET 提供的当前 Session 对象。Gets the current Session object provided by ASP.NET.

public:
 virtual property System::Web::SessionState::HttpSessionState ^ Session { System::Web::SessionState::HttpSessionState ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual System.Web.SessionState.HttpSessionState Session { get; }
member this.Session : System.Web.SessionState.HttpSessionState
Public Overridable ReadOnly Property Session As HttpSessionState

属性值

当前会话状态数据。The current session-state data.

属性

异常

将会话信息设置为 null 时发生。Occurs when the session information is set to null.

示例

下面的代码示例创建一个 GetStyle 函数,该函数检索在 Web 窗体页的会话状态中存储的密钥并将其值转换为字符串。The following code example creates a GetStyle function that retrieves a key stored in the session state of the Web Forms page and converts its value to a string.

// Create a private function that obtains
// information stored in Session state
// in the application's Global.asax file.
// When this method is called and a key name
// that is stored in Session state is passed
// as the paramter, the key is obtained and
// converted to a string.
String GetStyle(String key) {
  return Session[key].ToString();       
}
' Create a private function that obtains
' information stored in session state
' in the application's Global.asax file.
' When this method is called and a key name
' that is stored in session state is passed
' as the parameter, the key is obtained and
' converted to a string.
Function GetStyle(Key As String) As String
  Return Session(Key).ToString()
End Function

注解

此属性提供有关当前请求的会话的信息。This property provides information about the current request's session. 为每个请求 ASP.NET 应用程序中的页面或文档的用户维护一个 Session 对象。A Session object is maintained for each user that requests a page or document from an ASP.NET application. 当用户从应用程序中的页面移到页面时,不会丢弃 Session 对象中存储的变量;相反,只要用户访问应用程序中的页,这些变量就会保持不变。Variables stored in the Session object are not discarded when the user moves from page to page in the application; instead, these variables persist as long as the user is accessing pages in your application. 有关会话状态的详细信息,请参阅ASP.NET 会话状态概述For more information about session state, see ASP.NET Session State Overview.

适用于

另请参阅