【发布时间】:2016-01-15 17:49:03
【问题描述】:
我们有一个 ASP.NET MVC 5 应用程序,它一直在使用带有滑动过期的表单身份验证。我们最近切换到 OWIN Cookie 身份验证,但遇到会话无法正常扩展的问题。
以前,可以从 AJAX xhr 请求扩展会话。但是,使用这种配置,它们不会扩展。对于每个应该扩展的请求(GET 和 POST),我都会收到 200,即使在服务器终止会话之后也是如此。
当前设置是:
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext);
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType = "Cookies",
CookieSecure = CookieSecureOption.SameAsRequest,
CookieName = Constants.CatalystPortalCookieName,
LoginPath = new PathString(url.Action(nameof(LoginController.Index), "Login")),
SlidingExpiration = true,
ExpireTimeSpan = TimeSpan.FromMinutes(20),
CookiePath = "/",
});
但是,如果我单击导致整个页面作为文档响应加载的链接,则服务器会正确扩展会话。
【问题讨论】:
-
您是否使用 session.abandon 来终止会话/注销?如果是这样,那不是 OWIN 的正确方法。使用 OWIN,您应该使用 AuthenticationManager.SignOut 方法
-
如果您查看响应标头,您是否看到诸如 no-cache set 之类的东西?如果是这样,您可能会遇到 cookie 冲突问题:katanaproject.codeplex.com/…
-
打开fiddler 并检查请求/响应可能值得。
-
你是如何调用 ajax 请求的?一定要在使用jQuery时指定
cache:false; -
你找到答案了吗?
标签: c# ajax asp.net-mvc owin session-timeout