membership 鎖定用戶
microsoft 的membership提供了解鎖的功能,卻沒有提供鎖定功能,是因為這個鎖定是因為輸錯密碼超過了限定次數。如果要鎖定用戶,不允許登陸,可以更改IsApproved
示例如下:
如果要求解鎖
示例如下:
bool dirtyFlag = false;
MembershipUser mu = Membership.GetUser("cet");
bool isApproved = bool.Parse(TextBox1.Text);
if (mu.IsApproved != isApproved)
{
dirtyFlag = true;
mu.IsApproved = isApproved;
}
if (dirtyFlag == true)
{
Membership.UpdateUser(mu);//
}
MembershipUser mu = Membership.GetUser("cet");
bool isApproved = bool.Parse(TextBox1.Text);
if (mu.IsApproved != isApproved)
{
dirtyFlag = true;
mu.IsApproved = isApproved;
}
if (dirtyFlag == true)
{
Membership.UpdateUser(mu);//
}
如果要求解鎖
// 先解除鎖定
MembershipUser mu = Membership.GetUser("cet");
try
{
if (mu.IsLockedOut == true)
{
mu.UnlockUser(); //此处解除锁定
}
this.Label1.Text = "successful";
return;
}
catch (Exception exc)
{
this.Label1.Text = exc.Message; //此处加入你自己的异常处理代码
return;
}
MembershipUser mu = Membership.GetUser("cet");
try
{
if (mu.IsLockedOut == true)
{
mu.UnlockUser(); //此处解除锁定
}
this.Label1.Text = "successful";
return;
}
catch (Exception exc)
{
this.Label1.Text = exc.Message; //此处加入你自己的异常处理代码
return;
}