Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Problem with retrieving cookie in ASP.net

Reply
Thread Tools

Problem with retrieving cookie in ASP.net

 
 
SV
Guest
Posts: n/a
 
      05-07-2008
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
 
Reply With Quote
 
 
 
 
SV
Guest
Posts: n/a
 
      05-08-2008
Ahhh, It is solved now.

Thanks Mark.


On May 7, 6:26*pm, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> "SV" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> > Any help will be appreciated.

>
> Does this work: ?
>
> txt_unm.Text = Server.HtmlEncode(Request.Cookies("CTUserName").Va lue)
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


 
Reply With Quote
 
 
 
 
elizas elizas is offline
Junior Member
Join Date: Jan 2010
Location: India
Posts: 29
 
      04-28-2010
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
request.

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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving session data from a cookie Doug Jolley Ruby 0 02-20-2009 08:26 PM
Retrieving Forms Authentication Cookie angela ASP .Net 1 05-24-2005 06:47 PM
Cookie and Session Cookie Questions. Shapper ASP .Net 1 04-27-2005 11:20 AM
Session cookie? Browser instance cookie? Ben ASP .Net 3 06-03-2004 03:41 AM
Retrieving cookie data through document.cookie (Javascript) Vikram Bhatia Javascript 1 10-11-2003 12:54 PM



Advertisments