添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
public:
 property System::Web::SessionState::HttpSessionState ^ Session { System::Web::SessionState::HttpSessionState ^ get(); };
public System.Web.SessionState.HttpSessionState Session { get; }
member this.Session : System.Web.SessionState.HttpSessionState
Public ReadOnly Property Session As HttpSessionState
  • 启用了会话状态的 ASP.NET 应用程序。

  • 有权访问 Page.Session 属性的Web Forms页类,或任何有权访问 属性的 HttpContext.Current 类。

    string firstName = "Jeff";
    string lastName = "Smith";
    string city = "Seattle";
    // Save to session state in a Web Forms page class.
    Session["FirstName"] = firstName;
    Session["LastName"] = lastName;
    Session["City"] = city;
    // Read from session state in a Web Forms page class.
    firstName = (string)(Session["FirstName"]);
    lastName = (string)(Session["LastName"]);
    city = (string)(Session["City"]);
    // Outside of Web Forms page class, use HttpContext.Current.
    HttpContext context = HttpContext.Current;
    context.Session["FirstName"] = firstName;
    firstName = (string)(context.Session["FirstName"]);
    
    Dim firstName As String = "Jeff"
    Dim lastName As String = "Smith"
    Dim city As String = "Seattle"
    ' Save to session state in a Web Forms page class.
    Session("FirstName") = firstName
    Session("LastName") = lastName
    Session("City") = city
    ' Read from session state in a Web Forms page class.
    firstName = DirectCast(Session("FirstName"), String)
    lastName = DirectCast(Session("LastName"), String)
    city = DirectCast(Session("City"), String)
    ' Outside of Web Forms page class, use HttpContext.Current.
    Dim context As HttpContext = HttpContext.Current
    context.Session("FirstName") = firstName
    firstName = DirectCast(context.Session("FirstName"), String)
    	

    属性 Session 提供对 类的属性和方法的 HttpSessionState 编程访问。

    若要使用会话状态,必须启用它。 有关如何启用会话状态的信息,请参阅在 ASP.NET 会话状态概述配置会话状态。

    有关如何在会话状态中保存值的信息,请参阅 如何:在会话状态中保存值。 有关如何从会话状态读取值的信息,请参阅 如何:从会话状态读取值

  •