更新 : 2007 年 11 月
ASP.NET が提供している現在の Session オブジェクトを取得します。
名前空間 :
System.Web.UI アセンブリ :
System.Web (System.Web.dll 内)
<BrowsableAttribute(False)> _
Public Overridable ReadOnly Property Session As HttpSessionState
Dim instance As Page
Dim value As HttpSessionState
value = instance.Session
[BrowsableAttribute(false)]
public virtual HttpSessionState Session { get; }
[BrowsableAttribute(false)]
public:
virtual property HttpSessionState^ Session {
HttpSessionState^ get ();
}
/** @property */
/** @attribute BrowsableAttribute(false) */
public HttpSessionState get_Session()
public function get Session () : HttpSessionState
| 例外 | 条件 |
|---|
| HttpException |
セッション情報が nullNothingnullptrnull 参照 (Visual Basic では Nothing) に設定されると発生します。
|
このプロパティは、現在の要求のセッションに関する情報を提供します。ASP.NET アプリケーションからページまたはドキュメントを要求するそれぞれのユーザーについて Session オブジェクトが保持されます。Session オブジェクトに格納されている変数は、ユーザーがアプリケーション内でページ間を移動しても破棄されません。ただし、これらの変数が保持されるのは、ユーザーがアプリケーション内のページにアクセスしている間だけです。セッション状態の詳細については、「ASP.NET セッション状態の概要」を参照してください。
Web フォームのページのセッション状態に格納されているキーを取得し、その値を文字列に変換する GetStyle 関数を作成するコード例を次に示します。
' 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
// 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();
}
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
.NET Framework
サポート対象 : 3.5、3.0、2.0、1.1、1.0
参照