【发布时间】:2021-01-14 19:42:36
【问题描述】:
在我的应用程序中,一个按钮负责将用户重定向到登录页面,当它在 local server 上运行时,一切正常,在调用 Logout 方法后,它会生成一个空值 cookie 并将其放在回复:
public ActionResult Logout()
{
HttpContext context = HttpContext.Current;
context.Session.Abandon();
HttpCookie authenticationCookie = context.Request.Cookies[FormsAuthentication.FormsCookieName];
if (authenticationCookie == null)
authenticationCookie = new HttpCookie(FormsAuthentication.FormsCookieName);
authenticationCookie.Value = null;
authenticationCookie.Secure = true;
authenticationCookie.HttpOnly = true;
authenticationCookie.Expires = DateTime.Now.AddDays(-1);
context.Response.Cookies.Add(authenticationCookie);
return Redirect("~");
}
现在因为 cookie 没有价值,它会重定向到登录页面
在 global.asx 中检查身份验证信息
protected void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)
{
SUser user = new SUser();
user.ValidateAuthentication(args);
}
现在它重定向到登录页面
protected void Application_EndRequest(object sender, EventArgs e)
{
SUser.RedirectSsoAuthentication();
}
但是当应用程序在remote server 上运行时,Logout 似乎不起作用,它只是重定向到根路径
可能是我这边的代码遗漏了什么?
顺便说一句,更换浏览器并没有任何区别
我不确定,但可能与每个域的 cookie 限制有关。
如您所见,在响应中 cookie 没有任何值,但是当您发送请求时,cook 值是注销前的值
在不同的浏览器或不同的帐户上尝试没有问题!
【问题讨论】:
-
没人有办法!
-
偶尔会出现此问题,有时在两台服务器上都能正常工作。
标签: c# asp.net-mvc cookies httpcookie