0

我有Logout action一个控制器:

public ActionResult Logout()
{
    FormsAuthentication.SignOut();
    Session["UserCredential"] = null;
    return RedirectToAction("Index", "Home");
}

这在谷歌浏览器中工作。但是当我在第一次登录和注销后使用我的 web 应用程序和 firefox 浏览器(最新版本)时。当我再次登录应用程序并按下注销按钮时,我无法从 Web 应用程序注销。Request.IsAuthenticated正在返回我真正的价值。

对于登录,我使用了以下操作:

        [HttpPost]
        public JsonResult Login(string userName, string password)
        {

            User oUser = oRepository.GetUser(userName,password); 
            Session["UserCredential"] = oUser;


            if (oUser != null)
            {
                if (oUser.IsVerified)
                {
                    string url = Request.Url.AbsolutePath;    
                    FormsAuthentication.SetAuthCookie(userName, false);
                    return Json(new { res = 1, RedirectUrl = Url.Action("Index", "Home") }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json(new { res = 0, RedirectUrl = "" }, JsonRequestBehavior.AllowGet);
                }
            }

            return Json(new { res = -1, RedirectUrl = "" }, JsonRequestBehavior.AllowGet);
        }

任何人都知道我必须做些什么来解决我的Firefox浏览器问题。

4

1 回答 1

2

我不是 100% 肯定,但你可以试试这个。

我观察到该方法FormsAuthentication是在 ASP.NET 中实现的,该SignOut方法不会清除ASPXAUTHcookie。因此,在注销时,我通常会自己手动清除响应中的所有 cookie。

你可以尝试这样做。至少,在您的情况下,您应该清除 2 个 cookie:

1) FormsAuth cookie。CookieName您可以通过访问类的(或某些此类)静态字段来获取 cookie 的名称FormsAuthentication

2) ASP.NET 会话 cookie。检查即时窗口中的 cookie 名称(打印Cookies集合)。

要清除 cookie,只需向响应对象的 cookie 集合中添加与旧 cookie 同名的新 cookie,然后将它们的到期日期设置为过去的日期。

于 2013-04-14T19:03:32.090 回答