Reputation: 2048
I feel like I have been eaten by the cookie monster. I delete cookies and they come right back. On logout, I execute this code:
protected void Page_Load(object sender, EventArgs e)
{
DeleteCookie("UserId");
DeleteCookie("UserName");
Session.Abandon();
GoToPublicHomePage();
}
private void DeleteCookie(string name)
{
if (Request.Cookies[name] != null)
{
HttpCookie cookie = new HttpCookie(name);
cookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(cookie);
}
}
Just before the "GoToPublicHome()" call, I check the Request.Cookies and the UserId and UserName cookies are in Response.
In my Global.asax --> Session_Start code which executes immediately after the GoToPublicHome call, they have come back... like a bad penny.
Upvotes: 1
Views: 703
Reputation: 10413
The code you write instructs .Net to create a new HttpCookie, not to create "only if not exists". On the MSDN page there is an example: http://msdn.microsoft.com/en-us/library/system.web.httpcookie.aspx
Upvotes: 1