Problem with retrieving cookie in



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
ckUserName.Value = Trim(txt_unm.Text)
ckUserName.Expires =
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.





Jan 27, 2010
Reaction score
A brief idea about Cookie ASP.NET

What is a Cookie ?

A Cookie is an object is used to store the sort amount of data onto client end. It executes on server and resides on client browser.

How does Cookie work ?

when users request a page from your site, your application sends not just a page, but a cookie containing some data. When the user's browser gets the page, the browser also gets the cookie.Later, the user requests a page from your site again.If the cookie exists, the browser sends the cookie to your site along with the page

What are different type of Cookie?

Session Cookie : This Cookie will expire once the browser is closed.
Persistent Cookie : This Cookie will exists in browser till the time of expire.
How much can we store in a Cookie ?

Cookie specifications suggest that browsers should support a minimal number of cookies . In particular, an internet browser is expected to be able to store at least 300 cookies of four kilobytes each (both name and value count towards this 4 kilobyte limit), and at least 20 cookies per server or domain, so it is not a good idea to use a different cookie for each variable that has to be saved. It's better to save all needed data into one single cookie.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question