Remember me Next time
-
This checkbox on my login control has been working but now, the if i check teh Remember Me check box, teh login control does not remember my last login user name. see my code below I am using Internet explorer 6. Mozilla Firefox display the first 5 characters of my userID Imports FriendsTier Partial Class Login Inherits System.Web.UI.Page Dim oTier As FriendsTier = New FriendsTier Dim strUserID As String Dim strPassword As String Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'If IsPostBack Then 'on for the first time If Request.Cookies("loginuserid") IsNot Nothing Then Dim strUserID As String = Request.Cookies("loginuserid")("user") If strUserID IsNot Nothing Then myLogin.UserName = strUserID.ToString End If End If End Sub Protected Sub myLogin_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles myLogin.Authenticate strUserID = myLogin.UserName.Trim strPassword = myLogin.Password.Trim If Session("loginuserid") IsNot Nothing Then Session.Remove("loginuserid") End If If oTier.ValidMember(strUserID, strPassword) = True Then 'create the session vars Session("loginuserid") = strUserID 'grants the access, goto Destination url page e.Authenticated = True Else 'confirm that you are out e.Authenticated = False End If End Sub Protected Sub myLogin_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles myLogin.LoggedIn 'This event is fired when the Login button is pressed Dim chkRemember As CheckBox 'Since At the Conversion to html, the checkbox is named as login.ID along with the "$RememberMe". 'Since no such control (RememberMe) exist, you are getting error. 'always check whether the control exists ' If (Not Me.FindControl(myLogin.ID & "$RememberMe") Is Nothing) Then chkRemember = CType(Me.FindControl(myLogin.ID & "$RememberMe"), CheckBox) Else chkRemember = New CheckBox() End If If chkRemember.Checked = True Then 'cookies are sent to the user's pc using httpresponse Dim oCookie As HttpCookie = New HttpCookie("loginuserid") 'remove previous cookie