1

我已经使用 websecurity 类在 mvc4 中创建了一个帐户,如下所示:

 WebSecurity.CreateUserAndAccount(model.UserName, model.Password,
  new {  
           EmailAddress = model.EmailAddress, 
           ContactNo = model.ContactNo,
           Password = model.Password
       });

我的用户已成功创建......现在我想:随时激活/停用用户。

以便用户仅在其帐户处于活动状态时才登录,否则他将无法登录。

我怎样才能做到这一点?

4

1 回答 1

2

你可以使用UserProfile类来做到这一点。该类位于AccountModels充当每个用户帐户的配置文件表的类中。在这里,您通常希望包含一个名为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; }
}

您可以更改IsActive属性并在login操作中检查它。

有关更多信息,请参阅此帖子

于 2017-09-01T17:14:05.387 回答