好吧,我認爲這是相當自我解釋和有史以來最容易的事情。但出於某種原因,我無法讓這個工作。VB.net登錄嘗試計數器
Partial Class IntroductionPage 'CodeBehind for an ASPX Web page.
Public NumberOfAttempts As Integer = 0
Protected Sub PinButton_Click(sender As Object, e As System.EventArgs) Handles PinButton.Click
NumberOfAttempts = NumberOfAttempts + 1
'Query the database for the password, etc (omitted)...
If (x = 1 And NumberOfAttempts <= 10) Then
' Then Login the user successfully. (omitted)
Else
' The Pin was not found in the DB. We should throw error and make the validation label visible. (omitted)
End If
If (NumberOfAttempts > 10) Then
AttemptsErrorMessage.Visible = True
End If
End Sub
End Class
在測試中,我只是嘗試使用不正確的密碼登錄10次,但標籤不顯示。我每次都嘗試不同的密碼。另外,即使在10次嘗試之後,我嘗試了一個有效的密碼,然後程序仍然成功登錄了用戶(根據第一個if語句的邏輯,這應該不會有)。
我試圖按照這個資源,以及其他幾個描述完全相同的過程:How to count login attempts Visual Basic。 未來瀏覽者編輯/注意事項:本質上,似乎ASPX網頁的資源可能不正確。至少,我不能這樣做。請參閱下面的答案和評論。
在哪裏/如何定義NumberOfAttempts?在哪裏/如何定義「x」,它來自哪裏?你有沒有設置一個斷點來查看哪個部分不能按預期工作? – Plutonix
您確定標籤中有文字,並且不會隱藏在其他控件後面? – UnhandledExcepSean
這是一個網頁或Windows窗體? –