Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

remember user and auto login on webform

Hello experts, my remember me checkbox is not working for some reason the cookie doesn't contain a value, if i try to reload the page for a second time.  Basically i want my login to function like the EE website, where a user logins in and if his credentials are valid and he checks a checkbox, set up a cookie so next time the login doesn't get displayed.  My code is not working.

'Login Page
  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'Handles code for submit button
        lblStar.Visible = False
        lblError.Visible = False
        'jumps to the GetUser function which validates if the user exists
        If GetUser(txtUser.Text, txtPass.Text) Then
            'This function builds the cookie for each employee and sends information
            ' and is used when the Timecards webform is loaded
            GetData(txtUser.Text, txtPass.Text)
      'if checked setup a cookie to remember the employee
            If chkpasscheck.Checked = True Then
                Response.Cookies("toolname2").Value = "Accepted"
            End If
            lblError.Text = "Invalid Credentials: Please try again"
            lblError.Visible = True
            lblStar.Visible = True
        End If

   ' extra code here that finds the user from ms access database

    End Sub

 'The page that redirects too

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not Page.IsPostBack Then
                binddgforms("Select * From ToolRequest")
            End If
    End Sub
    Sub finduser()
        If Not (Request.Cookies("toolname2") Is Nothing) Then
          Exit Sub
       end if
    End Sub
1 Solution
'Sett the Cookie
Dim cookie1 As New System.Web.HttpCookie("thiscookie", "this is the cookie value")
cookie1.Expires = DateTime.Now.AddYears(1)

'Read the Cookie
If Not Request.Cookies("thiscookie") Is Nothing Then
End If


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now