我正在尝试找到一种方法来为我正在开发的应用程序的管理员提供一种有效的方法来快速锁定已经离开公司或被确定为行为的用户,该用户可以立即锁定或使用该应用程序.
到目前为止看起来我可以;
//enable the account to be locked out
_userManager.SetLockoutEnabledAsync(ApplicationUser user, true);
//Set an arbitrary date way into the future to lock them out until I want to unlock them
_userManager.SetLockoutEndDateAsync(ApplicationUser user, "01/01/2060");
Run Code Online (Sandbox Code Playgroud)
但如果用户的cookie过期时间为30分钟,则上述情况无法解决.这意味着,如果用户已经过身份验证,并且在我用于使Cookie保持有效的默认时间内,则用户可以继续使用该应用.
是否有用户管理器方法更改cookie被反弹的"检查"?我假设[Authorize]属性标签正在检查cookie,而不是在表中未公开的Identity内.想知道我如何更改"检查"值以使它们与cookie会话不匹配?
您如何为用户,角色和应用程序特定实体提供种子?似乎IdentityModel以自己的Context为目标?
internal sealed class Configuration : DbMigrationsConfiguration<Project.Models.SchoolContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
}
protected override void Seed(Project.Models.SchoolContext context)
{
// Seed the Entities
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" }
// );
//
}
}
Run Code Online (Sandbox Code Playgroud)
与
protected override void Seed(Project.Models.ApplicationDbContext context)
{
if (!context.Roles.Any(r => r.Name == "AppAdmin"))
{
var store = new RoleStore<IdentityRole>(context);
var manager = new RoleManager<IdentityRole>(store);
var role = new IdentityRole { Name = "AppAdmin" };
manager.Create(role); …Run Code Online (Sandbox Code Playgroud) 我坚持要在asp.net mvc核心应用程序中提供的解决方案.我想在Web应用程序中提供标准用户,角色,权限的解决方案,利用新的基于声明的方法.
我一直在关注Ben Foster的逻辑(http://benfoster.io/blog/asp-net-identity-role-claims).在下面的代码(演示质量)中,我将阐述我的方法,我将发表评论以帮助显示我快速而肮脏的测试解决方案.
我遇到的挑战是,它不起作用.
//注意:我发现了这个错误,并会在未来用户寻找类似解决方案的地方发表评论.
种子类:这是一个快速而肮脏的解决方案,可以为两个新用户,两个角色和一个角色的一些声明来种子数据库.我这是一个测试应用程序,用于学习管理我的应用程序授权的声明方法.我的完整解决方案将为每个租户提供一种方式,通过UI创建自己的角色,将1个或多个声明与角色相关联,然后为用户分配角色.我想为租户提供一种管理自己用户以及他们能做什么或不做什么的方法.这是基于声明的方法的简单实现,因为权利要求比与策略的1:1关系具有更多的权力.
public class DbInitializer
{
private ApplicationDbContext _context;
private RoleManager<ApplicationRole> _roleManager;
private UserManager<ApplicationUser> _userManager;
public DbInitializer(ApplicationDbContext context,RoleManager<ApplicationRole> roleManager, UserManager<ApplicationUser> userManager)
{
_roleManager = roleManager;
_userManager = userManager;
_context = context;
}
public async Task Initialize()
{
//RoleManager<IdentityRole> roleManager = new RoleManager<IdentityRole>();
//UserManager<ApplicationUser> userManager = new UserManager<ApplicationUser>();
_context.Database.EnsureCreated();
// Look for any students.
if (!_context.Users.Any())
{
//create user and admin role
ApplicationUser adminUser = new ApplicationUser();
adminUser.Email = "admin@company.com";
adminUser.UserName = "Admin";
var …Run Code Online (Sandbox Code Playgroud)