ASP.Net/Session Cookie/Session Mode

Материал из .Net Framework эксперт
Версия от 11:53, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Current session mode (VB.net)

<%@ Page Language="vb" %>
<html>
   <head>
      <title>Session property example</title>
      <script runat="server">
         Sub Page_Load()
            Message.Text = "Current Session State Mode: " & Session.Mode.ToString()
         End Sub
      </script>
   </head>
<body>
   <asp:label id="Message" runat="server"/>
</body>
</html>



Current Session State mode (VB.net)

<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    Session.TimeOut = 2
    lblMessage.Text = lblMessage.Text _
        & "Current Session State mode: " _
        & Session.Mode
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Session Properties</TITLE>
</HEAD>
<form runat="server">
<asp:label 
    id="lblMessage" 
    font-size="12pt"
    font-name="Tahoma"
    runat="server"
/>
</form>
</BODY>
</HTML>



Get current Session state mode (VB.net)

<%@ Page Language="vb" %>
<html>
   <head>
      <script runat="server">
         Sub Page_Load()
            Message.Text = "The current Session state mode is: " & _
               Session.Mode.ToString() & ".</br>"
         End Sub
      </script>
   </head>
<body>
   <asp:label id="Message" runat="server"/>
</body>
</html>



Session Abandon() (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>