Page.Session Page.Session Page.Session Page.Session Property

定義

取得 ASP.NET 提供的目前 Session 物件。Gets the current Session object provided by ASP.NET.

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; }
member this.Session : System.Web.SessionState.HttpSessionState
Public Overridable ReadOnly Property Session As HttpSessionState

屬性值

目前工作階段狀態資料。The current session-state data.

例外狀況

發生在工作階段資訊被設定為 null 時。Occurs when the session information is set to null.

範例

下列程式碼範例會建立GetStyle函式,此函式會抓取儲存在 Web form 頁面會話狀態中的金鑰,並將其值轉換成字串。The following code example creates a GetStyle function that retrieves a key stored in the session state of the Web Forms page and converts its value to a string.

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

備註

這個屬性會提供有關目前要求之會話的資訊。This property provides information about the current request's session. 系統會針對從 ASP.NET 應用程式要求頁面或檔的每個使用者維護物件。SessionA Session object is maintained for each user that requests a page or document from an ASP.NET application. 當使用者在應用Session程式中從頁面移至頁面時,不會捨棄儲存在物件中的變數; 相反地,只要使用者正在存取您應用程式中的頁面,這些變數就會保存。Variables stored in the Session object are not discarded when the user moves from page to page in the application; instead, these variables persist as long as the user is accessing pages in your application. 如需會話狀態的詳細資訊,請參閱ASP.NET 會話狀態總覽For more information about session state, see ASP.NET Session State Overview.

適用於

另請參閱