【发布时间】:2016-11-23 16:52:40
【问题描述】:
我的 owin 设置为使用基于 cookie 的身份验证和 OpenIdConnect,如下所示:
var options = new CookieAuthenticationOptions()
{
ExpireTimeSpan = TimeSpan.FromDays(30),
Provider = new CookieAuthenticationProvider {
OnValidateIdentity = cookieValidateIdentityContext =>
{
cookieValidateIdentityContext.Properties.ExpiresUtc = DateTime.UtcNow.AddMinutes(1);
return Task.FromResult(30);
}
}
}
app.UseCookieAuthentication(options);
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions() {.....})
我有一个像这样的静态 WebMethod
[WebMethod]
public static String GetJsonData(string query)
{
var user = HttpContext.Current.User.Identity.Name;
.....
}
这工作正常,但如果用户离开浏览器超过 20 分钟,身份验证失败。 HttpContext.Current.User.Identity.IsAuthenticated 为假。
即使我的 cookie 设置为 30 天后过期,也会发生这种情况。有什么方法可以强制验证 cookie 并进行身份验证?我没有使用基于表单的身份验证。
另外,一旦超过 20 分钟,cookieValidateIdentityContext 函数就不会被调用。如果我在 cookieValidateIdentityContext 中设置断点,在 20 分钟之前,断点被命中,但不是之后。
【问题讨论】:
标签: asp.net asp.net-mvc cookies owin