Session.Abandon() : Session class « Sessions « ASP.NET Tutorial






<%@ Page %>
<script language="C#" runat="server">
private void Page_PreRender(object sender, EventArgs e)
{
  if(Session["UserName"] != null) UserNameLabel.Text = Session["UserName"].ToString();
}

private void SaveButton_Click(object sender, System.EventArgs e)
{
  Session["UserName"] = UserNameTextBox.Text;
}

private void AbandonButton_Click(object sender, System.EventArgs e)
{
  Session.Abandon();
}
</script>
<html>
  <body>
    <form id="form1" method="post" runat="server">
      
        Update UserName in Session: <asp:TextBox id="UserNameTextBox" runat="server"></asp:TextBox>
        <asp:Button id="SaveButton" runat="server" Text="Save" OnClick="SaveButton_Click"></asp:Button>
      
        Current Session Contents: <br/>
        <asp:Label ID="UserNameLabel" Runat="server" EnableViewState="False"></asp:Label>
        <br/>
        <asp:Button id="RefreshButton" runat="server" Text="Refresh Without Saving"></asp:Button>
        <br/>
        Abandon Session - takes effect on *next* request since current request is still referring to Session.<br/>
        <asp:Button id="AbandonButton" runat="server" Text="Abandon Session" OnClick="AbandonButton_Click"></asp:Button>
      
      <a href="Default.aspx">VB Version - same session</a>
    </form>
  </body>
</html>








11.2.Session class
11.2.1.Session.Mode
11.2.2.Session.Abandon()
11.2.3.Use Session and Server.Transfer to create a wizard
11.2.4.Session.CodePage
11.2.5.Session.Contents.RemoveAll()
11.2.6.Session.CopyTo
11.2.7.Session.IsCookieless
11.2.8.Session.IsNewSession
11.2.9.Session.IsReadOnly
11.2.10.Session.Item
11.2.11.Session.Keys
11.2.12.Session.LCID
11.2.13.Session.Remove
11.2.14.Session.RemoveAll
11.2.15.Session.RemoveAt
11.2.16.Session.StaticObjects
11.2.17.Session.Timeout