2
Answers

How to Delete particular cookie in asp.net C#

Pothi Sam

Pothi Sam

10y
1.1k
1
my logout code are
   protected void Page_Load(object sender, EventArgs e)
    {
        //if (Request.Cookies["Prno"] != null)
        //{
        //    HttpCookie myCookie = new HttpCookie("Prno");
        //    myCookie.Value = String.Empty;
        //    myCookie.Expires = DateTime.Now.AddYears(-1);
        //    Response.Cookies.Add(myCookie);
        //    Response.Cookies.Remove("Prno");
        //}
        HttpCookie myCookie = new HttpCookie("Prno");
        //Here, we are setting the time to a previous time.
        //When the browser detect it next time, it will be deleted automatically.
        myCookie.Expires = DateTime.Now.AddDays(-1d);
        Response.Cookies.Add(myCookie);
        //Request.Cookies["Prno"].Expires = DateTime.Now;
        Session.Abandon();
        Session.Clear();
        Response.Cookies.Clear();
        Response.Redirect("~/Login.aspx");
    }
}
Answers (2)