如何在MVC中禁用用户帐户 [英] How to disable user account in mvc

查看:210
本文介绍了如何在MVC中禁用用户帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何禁用用户帐户,而不是在mvc5中将其删除.我正在使用默认值中已提供的asp.net身份.

我希望管理员可以禁用不再需要的用户帐户,并保留与其他表关联的用户数据.

How can I disable an account of a user instead of deleting it in mvc5. I am using the asp.net identity that is already provided in the default.

I want that administrator can disable the user accounts that are not no longer required and keep the user data that is associated in other tables

推荐答案

与MVC无关,但与您用于身份验证的任何提供程序有关.由于您对提供者的使用一无所知,因此无法回答您的问题.
This has nothing to do with MVC, but everything to do with whatever provider you''re using for authentication. Since you haven''t said anything at all about the provider your using it''s impossible to answer your question.


ASP.NET Identity 2.0模型中的LockoutEnabled标志意味着用户可以被锁定,而不是用户被锁定.

对于要被锁定的用户,LockoutEnabled必须为true,并且LockoutEndDateUtc必须大于当前日期.要全局启用锁定,必须在UserManager上将UserLockoutEnabledByDefault设置为true:

The LockoutEnabled flag in the ASP.NET Identity 2.0 model means that the user can be locked out, not that the user is locked out.

For a user to be locked out the LockoutEnabled must be true and LockoutEndDateUtc must be greater than the current date. To enable Locking out globally you must set UserLockoutEnabledByDefault to true on the UserManager:

public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
{
    var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));

	// Enable Lock outs
    manager.UserLockoutEnabledByDefault = true;
    manager.MaxFailedAccessAttemptsBeforeLockout = 5;

    // if you want to lock out indefinitely 200 years should be enough
    manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromDays(365*200);

	....
}



来源 [ ^ ]



Source[^]


这篇关于如何在MVC中禁用用户帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆