Problem with retrieving cookie in ASP.net

Discussion in 'ASP .Net' started by SV, May 7, 2008.

  1. SV

    SV Guest

    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
     
    SV, May 7, 2008
    #1
    1. Advertising

  2. SV

    SV Guest

    Ahhh, It is solved now.

    Thanks Mark.


    On May 7, 6:26 pm, "Mark Rae [MVP]" <> wrote:
    > "SV" <> wrote in message
    >
    > news:...
    >
    > > Any help will be appreciated.

    >
    > Does this work: ?
    >
    > txt_unm.Text = Server.HtmlEncode(Request.Cookies("CTUserName").Value)
    >
    > --
    > Mark Rae
    > ASP.NET MVPhttp://www.markrae.net
     
    SV, May 8, 2008
    #2
    1. Advertising

  3. SV

    elizas

    Joined:
    Jan 27, 2010
    Messages:
    27
    Location:
    India
    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
    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.
     
    elizas, Apr 28, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben
    Replies:
    3
    Views:
    1,191
  2. angela
    Replies:
    1
    Views:
    817
    Brock Allen
    May 24, 2005
  3. =?Utf-8?B?TnVubw==?=

    Convert a PHP cookie to an ASP.NET cookie

    =?Utf-8?B?TnVubw==?=, Jan 31, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    455
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jan 31, 2006
  4. william

    System.Net.Cookie vs System.Web.Cookie

    william, Apr 11, 2008, in forum: ASP .Net Security
    Replies:
    4
    Views:
    1,314
    Dominick Baier
    Apr 14, 2008
  5. Vikram Bhatia
    Replies:
    1
    Views:
    250
    kaeli
    Oct 11, 2003
Loading...

Share This Page