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 に設定されると発生します。

次のコード例では、GetStyleWeb 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 セッション状態の概要」を参照してください。

適用対象

こちらもご覧ください