Problem with retrieving cookie in ASP.net

  • Thread starter Thread starter SV
  • Start date Start date
S

SV

I have a login form with “Remember me on this computer” checkbox. I am
creating cookie if checkbox is checked. My code is:

If chk_remember.Checked = True Then

Dim ckUserName As HttpCookie = New
HttpCookie("CTUserName")
ckUserName.Value = Trim(txt_unm.Text)
ckUserName.Expires =
System.DateTime.Now.AddYears(4)
Response.Cookies.Add(ckUserName)
ckUserName = Nothing

End If


Now I am retrieving cookie on page load. It always gives me blank text
box of username. I don’t understand why it gives null. Is that I am
doing anything wrong?
My code for retrieving cookie is:

If Not (Request.Cookies("CTUserName") Is Nothing) Then

txt_unm.Text = Request.Cookies("CTUserName").Value

End If

Any help will be appreciated.

Thanks,
SV
 
Back
Top