Pothi Sam

Pothi Sam

  • NA
  • 335
  • 48.8k

How to Delete particular cookie in asp.net C#

Jan 7 2015 4:21 AM
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)