I have the following c# code running on inside a logout page, via a "logout" button. It works fine on ie and ff, but not on chrome. The issue is that chrome will not set the cookie. The value does not appear at all in the responce header. I have read some reports with similar issues on the net but no proper solution was proposed. Any help would be much appreciated. Thank you for your time. Here is the code that runs in the page:
public class LogOut : ExtendedControlBase
{
void RemoveCookie(string CookieName)
{
HttpCookie myCookie = new HttpCookie(CookieName);
myCookie.Expires = DateTime.Now.AddDays(-100);
Response.Cookies.Add(myCookie);
}
protected override void OnInit(EventArgs e)
{
Session.Remove("SiteUserEmail");
Session.Remove("SiteUserName");
Session.Remove("siteUserId");
Session.Remove("siteUserGroupId");
RemoveCookie("u");
Response.StatusCode = 301;
Response.AddHeader("Location", "/");
Response.Flush();
Response.End();
} 开发者_StackOverflow中文版
}
A few suggestions:
Try using something like Fiddler to see what exactly happening. My guess is actually the 'logout' link is not working on Chrome as expected.
Try setting the cookie header manually:
Response.AddHeader("Set-Cookie", "u=; expires=Fri, 31-Dec-1999 23:59:59 GMT");
Try setting test headers to check if they are really on the wire:
Response.AddHeader("X-Testing", "Testing");
Note: I haven't tried it. I assume setting arbitrary headers would work in Asp.Net.
My guess is that it's due to setting the expiration date in the past. Have you tried removing myCookie.Expires = DateTime.Now.AddDays(-100);
? I believe it will still be treated as a session cookie without that value since the expiration date will not be set in the future.
精彩评论