Private Sub cmdLogin_ServerClick(ByVal sender As Object, _
   ByVal e As System.EventArgs) Handles cmdLogin.ServerClick
   If Validateuser(txtUserName.Value,txtUserPass.Value) Then
      Dim tkt As FormsAuthenticationTicket
      Dim cookiestr As String
      Dim ck As HttpCookie
      tkt = New FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now(), _
dateTime.Now.AddMinutes(30), chkPersistCookie.Checked, "your custom data")
      cookiestr = FormsAuthentication.Encrypt(tkt)
      ck = new HttpCookie(FormsAuthentication.FormsCookieName(), cookiestr)
      if (chkPersistCookie.Checked) then ck.Expires=tkt.Expiration 
      ck.Path = FormsAuthentication.FormsCookiePath() 
      Response.Cookies.Add(ck)
      Dim strRedirect As String
      strRedirect = Request("ReturnURL")
      If strRedirect <> "" Then
         Response.Redirect(strRedirect, True)
      Else
         strRedirect = "default.aspx"
         Response.Redirect(strRedirect, True)
      End If
   Else
      Response.Redirect("logon.aspx", True)
   End If
End Sub