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

属性值

HttpSessionState

当前会话状态数据。

属性

例外

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

示例

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

// 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 会话状态概述

适用于

另请参阅