0
您好我的應用程序有兩種登錄類型,一種是Facebook,另一種是正常登錄。爲了區分它們並相應地設置值,我使用了cookie並在註銷事件中清除了這些內容。無法正確清除cookie
但是當我通過電子郵件和密碼登錄,然後註銷並再次通過Fb的登錄在UserCookie的cookie仍然堅持其進入到第一if語句再次
public ActionResult Logout(string returnUrl = "/")
{
try
{
FormsAuthentication.SignOut();
}
finally
{
if (Request.Cookies["UserCookie"] != null)
{
Request.Cookies["UserCookie"].Expires = DateTime.Now;
Request.Cookies["UserCookie"].Value = "";
}
if (Request.Cookies["fbUserUserID"] != null)
{
Request.Cookies["fbUserUserID"].Expires = DateTime.Now;
Request.Cookies["fbUserUserID"].Value = "";
}
if (Request.Cookies["fbFirstName"] != null)
{
Request.Cookies["fbFirstName"].Expires = DateTime.Now;
Request.Cookies["fbFirstName"].Value = "";
}
FederatedAuthentication.WSFederationAuthenticationModule.SignOut(true);
}
//return Redirect(returnUrl);
return View();
}
在我看來,我檢查像這樣
@if (HttpContext.Current.Request.Cookies["UserCookie"] != null && HttpContext.Current.Request.Cookies["UserCookie"].Value != "")
{
}
else if (HttpContext.Current.Request.Cookies["fbFirstName"] != null && HttpContext.Current.Request.Cookies["fbFirstName"].Value != "")
{
}
但餅乾其不清除我猜它顯示空字符串「」在控制器中的cookie的值,但我唐諾什麼鑑於發生。
有什麼我缺少的東西嗎?
謝謝你的工作。雖然我已經結束了嘗試,得到了解決方案,雖然如果(this.ControllerContext.HttpContext.Request.Cookies.AllKeys.Contains(「UserCookie」)) { HttpCookie cookie = this.ControllerContext.HttpContext.Request.Cookies [ 「UserCookie」]; cookie.Expires = DateTime.Now.AddDays(-1); this.ControllerContext.HttpContext.Response.Cookies.Add(cookie); } – Vivekh