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. General Programming
  3. C#
  4. how to clear cookie programitically

how to clear cookie programitically

Scheduled Pinned Locked Moved C#
tutorialquestion
3 Posts 1 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.
  • H Offline
    H Offline
    hotthoughtguy
    wrote on last edited by
    #1

    protected void btnAdd_Click(object sender, EventArgs e) { Response.Cookies[txtCookieValue.Text].Value = txtCookieValue.Text; DropDownList1.DataSource = Request.Cookies; DropDownList1.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { Response.Cookies.Clear(); Request.Cookies.Clear(); DropDownList1.DataBind(); } i have executed 1st method many times as to add more and more Cookies and then i have executed 2nd method ones.This should Clear all items in deopdownlist1. but its not cleared can anyone tell me why?

    H 1 Reply Last reply
    0
    • H hotthoughtguy

      protected void btnAdd_Click(object sender, EventArgs e) { Response.Cookies[txtCookieValue.Text].Value = txtCookieValue.Text; DropDownList1.DataSource = Request.Cookies; DropDownList1.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { Response.Cookies.Clear(); Request.Cookies.Clear(); DropDownList1.DataBind(); } i have executed 1st method many times as to add more and more Cookies and then i have executed 2nd method ones.This should Clear all items in deopdownlist1. but its not cleared can anyone tell me why?

      H Offline
      H Offline
      hotthoughtguy
      wrote on last edited by
      #2

      for (int i = 0; i < Response.Cookies.Count; i++) Response.Cookies[i].Expires = DateTime.Now.AddDays(-1); for (int i = 0; i < Request.Cookies.Count; i++) Request.Cookies[i].Expires = DateTime.Now.AddDays(-1); this is also not working

      H 1 Reply Last reply
      0
      • H hotthoughtguy

        for (int i = 0; i < Response.Cookies.Count; i++) Response.Cookies[i].Expires = DateTime.Now.AddDays(-1); for (int i = 0; i < Request.Cookies.Count; i++) Request.Cookies[i].Expires = DateTime.Now.AddDays(-1); this is also not working

        H Offline
        H Offline
        hotthoughtguy
        wrote on last edited by
        #3

        string[] c = Request.Cookies.AllKeys; foreach (string co in c) { Response.Cookies[co].Expires = DateTime.Now.AddDays(-1); } this is working.. any idea why this approach is right and above 2 are wrong?

        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