0
刪除這是我刪除所有cookie的方法:Cookie不能在註銷
private void ClearSessionAndCookies()
{
HttpContext.Current.Session.Remove(ExpirySession);
foreach (string cookieName in HttpContext.Current.Request.Cookies.AllKeys)
{
var cookie = new HttpCookie(cookieName)
{
HttpOnly = true,
Secure = Convert.ToInt32(ConfigurationManager.AppSettings["Https"]) == 1,
Domain = HttpContext.Current.Request.Cookies[cookieName].Domain,
Expires = DateTime.Now.AddDays(-1D)
};
HttpContext.Current.Response.SetCookie(cookie);
}
HttpContext.Current.Session.Abandon();
}
它完美其中在IIS中的所有網站在不同端口本地主機我開發的計算機上。但是,在QA環境中,每個網站都有不同的子域(qa.example.com,mz.example.com,cart.example.com),並且不會刪除Cookie。
我試着忽略cookie.Domain設置的行,沒有任何改變;萬一使用Cookies.Add和Cookies.Set試圖
另外,我用這段代碼在我傳統的ASP網站(mz.example.com),也完美地工作在我的電腦上:
For Each cookie in Response.Cookies
Response.Cookies(cookie).Expires = DateAdd("d",-1,now())
Next
在QA沒有,但舊代碼工作
Response.AddHeader "Set-Cookie", cookie & "=; Expires = Thu, 01-Jan-70 00:00:01 GMT; Path=/; HttpOnly; " & "Domain =" & Session("Domain")
我缺少相關的不同的子域的東西嗎?所有網站中的域都設置爲「.example.com」。