Important: Version 1.0 of the reCAPTCHA API is no longer supported, please upgrade to Version 2.0. Learn more
The reCAPTCHA ASP.NET Library provides a simple way to place a CAPTCHA on your ASP.NET website, helping you stop bots from abusing it. The library wraps the reCAPTCHA API. You can use the library from any .NET language including C# and Visual Basic .NET.
To use reCAPTCHA with ASP.NET, you can download the reCAPTCHA ASP.NET library.
After you've signed up for your API keys, below are basic instructions for installing reCAPTCHA on your site with ASP.NET:
- Add a reference on your website to library/bin/Release/Recaptcha.dll: On the Visual Studio Website menu, choose Add Reference and then click the .NET tab in the dialog box. Select the Recaptcha.dll component from the list of .NET components and then click OK. If you don't see the component, click the Browse tab and look for the assembly file on your hard drive.
- Insert the reCAPTCHA control into the form you wish to protect by adding the following code snippets:
At the top of the aspx page, insert this:
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
Then insert the reCAPTCHA control inside of the <form runat="server"> tag:
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" PublicKey="your_public_key" PrivateKey="your_private_key" />
You will need to substitute your public and private key into PublicKey and PrivateKey respectively.
- Make sure you use ASP.NET validation to validate your form (you should check Page.IsValid on submission).
The following is a "Hello World" with reCAPTCHA using Visual Basic. A C# sample is included with the library download.
<%@ Page Language="VB" %> <%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %> <script runat=server%gt; Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) If Page.IsValid Then lblResult.Text = "You Got It!" lblResult.ForeColor = Drawing.Color.Green Else lblResult.Text = "Incorrect" lblResult.ForeColor = Drawing.Color.Red End If End Sub </script> <html> <body> <form runat="server"> <asp:Label Visible=false ID="lblResult" runat="server" /> <recaptcha:RecaptchaControl ID="recaptcha" runat="server" Theme="red" PublicKey="your_public_key" PrivateKey="your_private_key" /> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" /> </form> </body> </html>