我尝试使用像......这样的用户登录。
var accessor = HttpContext.Current.GetOwinContext().Get<ApplicationSignInManager>();
var result = await accessor.CreateUserIdentityAsync(new User() { ... });
AuthenticationManager.SignIn(
new AuthenticationProperties { AllowRefresh = false, IsPersistent = false },
result);
并且SignIn正常工作,但是如果我刷新页面,用户仍然会通过身份验证,我希望用户可以注销,因为我将AllowRefresh
和IsPersistent
都设置为false。我错过了一些明显的东西吗或者也许是不明显的事情? (如果它有所不同,登录的用户实际上并不存在,它是一种匿名认证用户)。
答案 0 :(得分:1)
AllowRefresh是一个设置,允许/禁止在您请求时刷新cookie(例如,更新到期时间)。
如果刷新页面,是否仍然需要进行身份验证,这与此无关。
bool? allowRefresh = authenticationTicket.Properties.AllowRefresh;
if (issuedUtc.HasValue && expiresUtc.HasValue && base.Options.SlidingExpiration && (!allowRefresh.HasValue || allowRefresh.Value))
{
TimeSpan t = utcNow.Subtract(issuedUtc.Value);
TimeSpan t2 = expiresUtc.Value.Subtract(utcNow);
if (t2 < t)
{
this._shouldRenew = true;
this._renewIssuedUtc = utcNow;
TimeSpan timeSpan = expiresUtc.Value.Subtract(issuedUtc.Value);
this._renewExpiresUtc = utcNow.Add(timeSpan);
}
}