大佬教程收集整理的这篇文章主要介绍了asp.net – 禁用ASPNET标识2.0中的用户,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
有一个新的锁定功能,但是似乎锁定可以被控制以禁用用户,但只有在一定数量的错误密码尝试之后才锁定用户。
任何其他选项?
// You can add profile data for the user by adding more properties to your ApplicationUser class,please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more. public class ApplicationUser : IdentityUser
在这里有一个很好的链接,为了轻松点击here
本教程将准确地告诉您需要添加用户的自定义属性。
实际上,甚至不要再看教程。
1)将一个属性添加到ApplicationUser类中,例如:
public bool? IsEnabled { get; set; }
2)在数据库的AspNetUsers表上添加一个名称相同的列。
3)繁荣,就是这样!
现在在您的AccountController中,您具有以下注册操作:
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email,Email = model.Email,IsEnabled = true }; var result = await UseRMANager.CreateAsync(user,model.password); if (result.Succeeded)
在创建ApplicationUser对象时,我添加了IsEnabled = true。该值现在将保留在AspNetUsers表中的新列中。
然后,您需要通过覆盖ApplicationSignInManager中的passwordSignInAsync来处理该值的检查,作为登录过程的一部分。
我做到了如下:
public override Task<SignInStatus> passwordSignInAsync(String userName,String password,bool rememberMe,bool shouldLockout) { var user = UseRMANager.FindByEmailAsync(userName).Result; if ((user.IsEnabled.HasValue && !user.IsEnabled.value) || !user.IsEnabled.Hasvalue) { return Task.FromResult<SignInStatus>(SignInStatus.LockedOut); } return base.passwordSignInAsync(userName,password,rememberMe,shouldLockout); }
以上是大佬教程为你收集整理的asp.net – 禁用ASPNET标识2.0中的用户全部内容,希望文章能够帮你解决asp.net – 禁用ASPNET标识2.0中的用户所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。