Page.Session 属性
.NET Framework 类库
Page.Session 属性
获取 ASP.NET 提供的当前 Session 对象。
命名空间:System.Web.UI
程序集:System.Web(在 system.web.dll 中)
语法Visual Basic(声明)
Public Overridable ReadOnly Property Session As HttpSessionState
Visual Basic(用法)
Dim instance As Page Dim value As HttpSessionState value = instance.Session
C#
public virtual HttpSessionState Session { get; }
C++
public: virtual property HttpSessionState^ Session { HttpSessionState^ get (); }
J#
/** @property */
public HttpSessionState get_Session ()
JScript
public function get Session () : HttpSessionState
属性值
当前会话状态数据。
备注该属性提供有关当前请求的会话的信息。为从 ASP.NET 应用程序请求页或文档的每个用户维护一个 Session 对象。当用户在应用程序中从一页移动到另一页时,存储在 Session 对象中的变量不会被放弃;相反,只要用户在应用程序中访问页,这些变量就将保持。有关会话状态的更多信息,请参见 ASP.NET 会话状态。
示例下面的代码示例创建一个 GetStyle 函数,该函数检索 Web 窗体页会话状态中存储的键,并将其值转换为字符串。
Visual Basic
复制到剪贴板
' 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
C#
复制到剪贴板
// 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(); }

浙公网安备 33010602011771号