tar*_*all 2 c# owin asp.net-identity
我正在尝试使用类似...的内容登录用户。
var accessor = HttpContext.Current.GetOwinContext().Get<ApplicationSignInManager>();
var result = await accessor.CreateUserIdentityAsync(new User() { ... });
AuthenticationManager.SignIn(
new AuthenticationProperties { AllowRefresh = false, IsPersistent = false },
result);
Run Code Online (Sandbox Code Playgroud)
和登入工作,但如果我刷新页面,用户通过身份认证,在那里我会希望被注销的用户,因为我同时设置AllowRefresh并IsPersistent为false。我错过了一些明显的东西吗?或者也许是一些不明显的东西?(如果它有所作为,则登录的“用户”实际上并不存在,它是一种匿名的经过身份验证的用户)。
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);
}
}
Run Code Online (Sandbox Code Playgroud)