Integrare Google ReCaptcha con asp.net
Per far funzionare il ReCaptcha di Google bisogna prima di tutto creare una Chiave privata dalla Dashboard sviluppatore.
Aggiungere poi le dll nella directory bin.
Aggiungere il TagPrefix nella pagina:
- <%@ Register Assembly=”Recaptcha.Web” Namespace=”Recaptcha.Web.UI.Controls” TagPrefix=”cc1″ %>
- <cc1:recaptcha id=”Recaptcha1″ runat=”server” ></cc1:recaptcha>
- <asp:Label ID=”lblResponse” runat=”server” Text=””></asp:Label>
Nel file di sviluppo inserire
Imports Recaptcha.Web
If String.IsNullOrEmpty(Recaptcha1.Response) Then
lblResponse.Text = “CAPTCHA text cannot be blank.”
Else
Dim result As RecaptchaVerificationResult = Recaptcha1.Verify()
If result = RecaptchaVerificationResult.Success Then
…….inserire l’azione del button qui
End If
If result = RecaptchaVerificationResult.IncorrectCaptchaSolution Then
lblResponse.Text = “Il controllo è errato. Riprova!”
End If
End If