[英]Asp.Net Mvc4 WebSecurity How to activate or deactivate a user account
I have create an account in mvc4 using the websecurity class as follow : 我已经使用websecurity类在mvc4中创建了一个帐户,如下所示:
WebSecurity.CreateUserAndAccount(model.UserName, model.Password,
new {
EmailAddress = model.EmailAddress,
ContactNo = model.ContactNo,
Password = model.Password
});
My user have created successfully ... now i want to : activate/deactivate a user whenever i wish. 我的用户已成功创建...现在,我想:随时激活/停用用户。
so that user login only if his account is active otherwise he shouldn't be able to login . 因此只有用户的帐户处于活动状态时才登录,否则他将无法登录。
How can i achieve this? 我怎样才能做到这一点?
You can use UserProfile
class for do it. 您可以使用
UserProfile
类来实现。 This class located in the AccountModels
class which acts as a profile table for each user account. 此类位于
AccountModels
类中,该类充当每个用户帐户的配置文件表。 It is here that you'd typically want to include a property named IsActive
. 您通常希望在这里包括一个名为
IsActive
的属性。
[Table("UserProfile")]
public class UserProfile
{
[key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string Email { get; set; }
public bool IsActive { get; set; }
}
You can change IsActive
property and check it in login
action. 您可以更改
IsActive
属性并在login
操作中对其进行检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.