我正在尝试显示用户帐户何时自动解锁的计数器。
我希望存储在unlockCounter中的计数器只显示剩余的分钟数。
unlockDate是以如下格式存储的DateTime:11/29/2014 1:06:05 PM。
编辑:这最终是我提出的完美工作。更新以防其他人感兴趣。
If (CurrentUser IsNot Nothing) Then
If (CurrentUser.IsLockedOut) Then
Dim lastLockout As DateTime = CurrentUser.LastLockoutDate
Dim unlockDate As DateTime = lastLockout.AddMinutes(Membership.PasswordAttemptWindow).AddSeconds(-1)
Dim unlockCounterMinutes As String = unlockDate.Subtract(DateTime.Now).Minutes + 1
Dim unlockCounterSeconds As String = unlockDate.Subtract(DateTime.Now).Seconds
If (unlockCounterMinutes > 1) Then
LoginUser.FailureText = "Your account has been locked - Please try again in " & unlockCounterMinutes & " Minutes"
ElseIf (unlockCounterSeconds > 1) Then
LoginUser.FailureText = "Your account has been locked - Please try again in " & unlockCounterSeconds & " Seconds"
Else
LoginUser.FailureText = "Your account is now being unlocked - Please login again"
End If
End If
End If
答案 0 :(得分:0)
使用unlockDate.Subtract(DateTime.Now)
获取剩余时间窗口的Timespan
个对象。
根据您想要的粒度,TotalMinutes
或TotalSeconds
为正时,请勿让用户进入。