how to clear cookie programitically
-
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?
-
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?
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
-
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
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?