ASP.Net/Session Cookie/Session ID — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 11:53, 26 мая 2010

Get session id if it is a new session (VB.net)

<%@ Page Language="vb" %>
<html>
   <head>
      <script runat="server">
         Sub Page_Load()
            If Session.IsNewSession Then
               Message.Text = "The current Session (SessionID: " & _
                  Session.SessionID & ") was created with this request."
            Else
               Message.Text = "The current Session (SessionID: " & _
                  Session.SessionID & ") existed prior to this request."
            End If
         End Sub
      </script>
   </head>
<body>
   <asp:label id="Message" runat="server"/>
</body>
</html>



Is this session a new session (VB.net)

<%@ Page Language="vb" %>
<html>
   <head>
      <script runat="server">
         Sub Page_Load()
            If Not IsPostBack
               If Session.IsNewSession Then
                  Session("key1") = "value1"
                  Message.Text = "The current Session (SessionID: " & _
                     Session.SessionID & ") was created with this request."
               Else
                  Message.Text = "Click the button to abandon the current session."
                  Dim AbandonButton As New Button
                  AbandonButton.Text = "Abandon Session"
                  myForm.Controls.Add(AbandonButton)
               End If
            Else
               Session.Abandon()
               Message.Text = "Session abandoned."
            End If
         End Sub
      </script>
   </head>
<body>
   <form id="myForm" runat="server">
      <asp:label id="Message" runat="server"/>
   </form>
</body>
</html>