ASP.NET Session Login Form

 

   1.aspx
 
   <div>
 
      <asp:MultiView ID="MultiView1" runat="server">
 
         <asp:View ID="View0" runat="server">
 
            <asp:Table ID="Table1" runat="server">
 
               <asp:TableRow>
                  <asp:TableCell ColumnSpan="2">
                     <asp:Label ID="Label1" runat="server" Text="Page1 Login Form" Font-Bold="True" />
                  </asp:TableCell>
               </asp:TableRow>
 
               <asp:TableRow>
                  <asp:TableCell>Login:</asp:TableCell>
                  <asp:TableCell><asp:TextBox ID="TextBox1" runat="server" /></asp:TableCell>
               </asp:TableRow>
 
               <asp:TableRow>
                  <asp:TableCell>Password:</asp:TableCell>
                  <asp:TableCell><asp:TextBox ID="TextBox2" runat="server" /></asp:TableCell>
               </asp:TableRow>
 
               <asp:TableRow>
                  <asp:TableCell></asp:TableCell>
                  <asp:TableCell><asp:Button ID="Button1" runat="server" Text="Login" /></asp:TableCell>
               </asp:TableRow>
 
            </asp:Table>
 
         </asp:View>
 
         <asp:View ID="View1" runat="server">
 
            <asp:Label ID="Label2" runat="server" Text="Page1 Login Complete" Font-Bold="True" /><br />
            <asp:Button ID="Button2" runat="server" Text="Logout" /><br />
            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="2.aspx">Page 2</asp:HyperLink>
 
         </asp:View>
 
      </asp:MultiView>
 
   </div>
 

 

   1.aspx.vb
 
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
      If Session("IsPass") Is Nothing Then
         MultiView1.ActiveViewIndex = 0
      Else
         MultiView1.ActiveViewIndex = 1
      End If
 
   End Sub
 
   Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
      If TextBox1.Text = "A" And TextBox2.Text = "A" Then
         Session("IsPass") = True
         Session.Timeout = 1
         Response.Redirect("1.aspx")
      End If
   End Sub
 
   Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
      Session.Abandon()
      Response.Redirect("1.aspx")
   End Sub
 

 

   2.aspx
 
   <div>
 
      <asp:Label ID="Label1" runat="server" Text="Page 2" Font-Bold="True" /><br />
      <asp:Button ID="Button1" runat="server" Text="Logout" /><br />
      <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="1.aspx">Page 1</asp:HyperLink>
 
   </div>
 

 

   2.aspx.vb
 
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      If Session("IsPass") Is Nothing Then
         Response.Redirect("1.aspx")
      End If
   End Sub
 
   Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
      Session.Abandon()
      Response.Redirect("1.aspx")
   End Sub