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. ASession物件保留在每個要求的頁面或文件中 ASP.NET 應用程式的使用者。A 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.

適用於

另請參閱