看看ASP.NET Identity(ASP.NET中的新成员实现),我在实现自己的时遇到了这个界面UserStore:
//Microsoft.AspNet.Identity.Core.dll
namespace Microsoft.AspNet.Identity
{
public interface IUserSecurityStampStore<TUser> :
{
// Methods
Task<string> GetSecurityStampAsync(TUser user);
Task SetSecurityStampAsync(TUser user, string stamp);
}
}
Run Code Online (Sandbox Code Playgroud)
IUserSecurityStampStore由默认实现EntityFramework.UserStore<TUser>,实质上获取和设置TUser.SecurityStamp属性.
经过一些挖掘之后,似乎a SecurityStamp是Guid在关键点新生成的UserManager(例如,更改密码).
因为我在Reflector中检查这段代码,所以我无法真正破译.几乎所有的符号和异步信息都已经过优化.
此外,谷歌也没有太多帮助.
SecurityStampASP.NET标识,它用于什么?SecurityStamp创建身份验证cookie时,是否扮演任何角色?源代码在这里:
那么什么是ASP.NET Identity的IUserSecurityStampStore <TUser>接口?我们了解到ASP.NET Identity具有安全标记功能,用于使用户登录cookie无效,并强制他们重新登录.
在我的MVC应用程序中,管理员可以归档用户.当拱形时,它们应该立即被注销并被迫再次登录(这将因为它们被存档而拒绝它们).
我怎样才能做到这一点?我知道安全标记是关键.默认设置如下所示:
app.UseCookieAuthentication(new CookieAuthenticationOptions {
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider {
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
Run Code Online (Sandbox Code Playgroud)
通过实验,如果我将validateInterval设置为1分钟,然后在数据库中手动破解用户安全标记,那么他们将被迫重新登录,但仅在该时间段过去之后.
有没有办法让这个瞬间,或者只是将间隔设置为一个低时间段并等待(或实现我自己的OnValidateIdentity检查每个请求)
谢谢
asp.net authentication asp.net-mvc asp.net-mvc-5 asp.net-identity