How to User Remember Me on Login By HTTPCookie
On Every application has the option to hold the User Name and Password by default on the website, either we can use it or not. On the Post going to give information on how to store cookies on browser till we clear the browser cookies. Coding as Below
First How to check where any cookies is available or set by User on VB coding :
Dim UserName as String
Dim Password as String
Dim aCookie As HttpCookie = Request.Cookies("AppName")
If Not Request.Cookies("AppName") Is Nothing Then
If Not aCookie.Values("User") Is Nothing And Not aCookie.Values("Pass") Is Nothing Then
UserName = aCookie.Values("User").ToString()
Password = aCookie.Values("Pass").ToString()
btnLogin.Focus()
ElseIf Not aCookie.Values("User") Is Nothing Then
UserName = aCookie.Values("User").ToString()
End If
End If
On Add Cookies on Browser :
Dim aCookie As HttpCookie = New HttpCookie("AppName")
aCookie.Values.Add("User", UserName)
aCookie.Values.Add("Pass", Password)
Response.Cookies.Add(aCookie)
aCookie.Expires = Date.MaxValue
To Clear Cookies on Browser :
Dim aCookie As HttpCookie = Request.Cookies("AppName")
aCookie.Values.Remove("User")
aCookie.Values.Remove("Pass")
Response.Cookies.Add(aCookie)
aCookie.Expires = Date.MaxValue
By this we can able to have some information on the browser instead of using Session to store user name and password while the browser is closed the data will lose.
This is the best way to use Remember Me Option on the Website's
Comments
Post a Comment