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 Form頁面會話狀態的金鑰,並將其值轉換成字串。

// 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 會話狀態概觀

適用於

另請參閱