End a session by calling Session.Abandon (C#) : Abandon « Sessions « ASP.NET Tutorial

ASP.NET Tutorial
1. ASP.Net Instroduction
2. Language Basics
3. ASP.net Controls
4. HTML Controls
5. Page Lifecycle
6. Response
7. Collections
8. Validation
9. Development
10. File Directory
11. Sessions
12. Cookie
13. Cache
14. Custom Controls
15. Profile
16. Configuration
17. LINQ
18. ADO.net Database
19. Data Binding
20. Ajax
21. Authentication Authorization
22. I18N
23. Mobile
24. WebPart
25. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.NET Tutorial » Sessions » Abandon 
11. 1. 1. End a session by calling Session.Abandon (C#)
<%@ Page Language="C#" %>

<script runat="server">
   void Submit_Click(Object Sender, EventArgs e) {
      if (tbPass.Value == "mypass") {
         Session["UserName"= tbUser.Value;
         Response.Redirect("NextPage.aspx");
      else {
         Label1.Text = "<font color=red>That " "is the wrong password!</font>";
      }
   }
</script>

<html>
<body>
   <form runat="server">
      Please enter your username and password:
      <input type="text" id="tbUser" runat="server"/><br>
      <input type="password" id="tbPass" runat="server"/>
      
      
      <asp:Button id="btSubmit" text="Submit" runat="server" OnClick="Submit_Click" />
      <asp:Label id="Label1" runat="server"/>
   </form>
</body>
</html>


File: NextPage.aspx

<%@ Page Language="VB" %>

<script runat="server">
   sub Page_Load(Sender as Object, e as EventArgs)
      if not Page.IsPostBack then
         Label1.Text = "Welcome " & Session("Username"& _
            "!"
         
         Label1.Text = Label1.Text & "The current time is: " & _
            DateTime.Now.ToString("T"""
      
         Label1.Text = Label1.Text & "Your session id is: " & _
            Session.SessionID & ""
      end if
   end sub
   
   sub Submit_Click(obj as object, e as eventargs)
      Session.Abandon
      Label1.Text = "Your session has ended."
      btSubmit.Visible = false
   end sub
</script>

<html><body>
   <form runat="server">
      <asp:Label id="Label1" runat="server"/>
      
      <asp:Button id="btSubmit" 
         text="Submit"
         runat="server"
         OnClick="Submit_Click" />
   </form>
</body></html>
11. 1. Abandon
11. 1. 1. End a session by calling Session.Abandon (C#)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.