Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Cookies not working

Cookies not working

Scheduled Pinned Locked Moved ASP.NET
sysadminhelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amittinku
    wrote on last edited by
    #1

    Hi, Just a small code to check whether cookies are getting stored/retrived or not. Check the code below: protected void Button1_Click(object sender, EventArgs e) { Response.Cookies["userName"].Value = "patrick"; } protected void Button2_Click(object sender, EventArgs e) { if (Request.Cookies["userName"] == null) Label1.Text = "Cookie not found"; else Label1.Text=Server.HtmlEncode(Request.Cookies["userName"].Value); } ------------------------ When I try to retrieve the cookie values on button2_click, it is not retrieved although I have set the option "accept all cookies" in IE 6. Where is issue?

    A A 2 Replies Last reply
    0
    • A amittinku

      Hi, Just a small code to check whether cookies are getting stored/retrived or not. Check the code below: protected void Button1_Click(object sender, EventArgs e) { Response.Cookies["userName"].Value = "patrick"; } protected void Button2_Click(object sender, EventArgs e) { if (Request.Cookies["userName"] == null) Label1.Text = "Cookie not found"; else Label1.Text=Server.HtmlEncode(Request.Cookies["userName"].Value); } ------------------------ When I try to retrieve the cookie values on button2_click, it is not retrieved although I have set the option "accept all cookies" in IE 6. Where is issue?

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Is this happening between postbacks. I think it should work if you are not working cookieless. I checked and found working. :confused: Also check whether you have re initialized the value on page_load section.

      Abhishek Sur


      My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

      **Don't forget to click "Good Answer" if you like to.

      A 1 Reply Last reply
      0
      • A Abhishek Sur

        Is this happening between postbacks. I think it should work if you are not working cookieless. I checked and found working. :confused: Also check whether you have re initialized the value on page_load section.

        Abhishek Sur


        My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

        **Don't forget to click "Good Answer" if you like to.

        A Offline
        A Offline
        amittinku
        wrote on last edited by
        #3

        I have not written anything in page_load. Just this small code. Moreover, when i try to see cookies folder, no such cookie is there. I am running this web page on my machine only i.e. no webserver, just a local host.

        1 Reply Last reply
        0
        • A amittinku

          Hi, Just a small code to check whether cookies are getting stored/retrived or not. Check the code below: protected void Button1_Click(object sender, EventArgs e) { Response.Cookies["userName"].Value = "patrick"; } protected void Button2_Click(object sender, EventArgs e) { if (Request.Cookies["userName"] == null) Label1.Text = "Cookie not found"; else Label1.Text=Server.HtmlEncode(Request.Cookies["userName"].Value); } ------------------------ When I try to retrieve the cookie values on button2_click, it is not retrieved although I have set the option "accept all cookies" in IE 6. Where is issue?

          A Offline
          A Offline
          amittinku
          wrote on last edited by
          #4

          The above code is working now. IF i write the below: Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1); There could be any value of expiry. Why is it mandatory? I mean if we donot set it, does it mean it will not create at all. Moreover, without seeing the code, how to verify the expiry time of a cookie?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups