Page.Session 属性

定义

获取 ASP.NET 提供的当前 Session 对象。

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; }
[<System.ComponentModel.Browsable(false)>]
member this.Session : System.Web.SessionState.HttpSessionState
Public Overridable ReadOnly Property Session As HttpSessionState

属性值

当前会话状态数据。

属性

例外

将会话信息设置为 null 时发生。

示例

下面的代码示例创建一个 GetStyle 函数,该函数检索存储在 Web 窗体页的会话状态中的密钥,并将其值转换为字符串。

// 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

注解

此属性提供有关当前请求的会话的信息。 Session为从 ASP.NET 应用程序请求页面或文档的每个用户维护对象。 当用户在应用程序中 Session 从一个页面移动到一个页面时,不会放弃存储在 对象中的变量;相反,只要用户访问应用程序中的页面,这些变量就会保留。 有关会话状态的详细信息,请参阅 ASP.NET 会话状态概述

适用于

另请参阅