lock lock - 25 days ago 12
C# Question

how to delete cookies in asp.net website

In my website when user clicks on logout button. Logout.aspx page loads with code

Session.Clear()
; in ASP.NET/C# do this clear all cookies? Or is there any other code to be added to remove all the cookies of my website?

Answer

Try something like that:

if (Request.Cookies["userId"] != null)
{
    Response.Cookies["userId"].Expires = DateTime.Now.AddDays(-1);   
}

But it also makes sense to use

Session.Abandon();

besides in many scenarios.

Comments