usesessionsolved.aspx

来自「Other things about csharp. you could lea」· ASPX 代码 · 共 34 行

ASPX
34
字号
<%@ Import Namespace="System.Net" %>
<%@ Page Debug="true" %>

<Script Language="C#" runat="Server">

private CookieCollection _cookieJar;

public void Page_Load(Object sender, EventArgs e)
{
  SessionStateExample sessionExample = new SessionStateExample();
  Cookie sessionCookie;
  CookieContainer cookieContainer = new CookieContainer();
  CookieCollection cookieCollection = new CookieCollection();

  sessionExample.CookieContainer = cookieContainer;

  sessionCookie = (Cookie)Session["sessionCookie"];

  if (sessionCookie == null)
  {
    sessionExample.SetSession("name", "rob");
    cookieCollection = sessionExample.CookieContainer.GetCookies(new Uri("http://localhost"));
    Session["sessionCookie"] = cookieCollection["ASP.NET_SessionId"];
  }
  else
    sessionExample.CookieContainer.Add(sessionCookie);
  
  lblSession1.Text = sessionExample.GetSession("name");
}

</Script>
<Font face=arial>
Value: <asp:label id="lblSession1" runat="server"/>
</Font>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?