reCAPTCHA logo

ASP.NET Library for reCAPTCHA

The reCAPTCHA ASP.NET Library provides a simple way to place a CAPTCHA on your ASP.NET website, helping you stop bots from abusing your website. The library wraps the reCAPTCHA API. You can use the library from any .NET language including C# and Visual Basic .NET.

reCAPTCHA Quickstart

These instructions should get you started quickly.

  1. Download the reCAPTCHA Library.
  2. Add a reference to library/bin/Release/Recaptcha.dll to your website
  3. Insert the reCAPTCHA control into the form you wish to protect. At the top of the aspx page, insert the following code:
    <%@ 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=""            
      PrivateKey=""
      />
    
  4. If you haven't done so, sign up for an API key. Put the public and private key in the PublicKey and PrivateKey properties
  5. Make sure you use ASP.NET validation to validate your form (you should check Page.IsValid on submission)

Example

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>
    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"
            PublicKey=""            
            PrivateKey=""
            />
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
    </form>
</body>
</html>

Customizing client side behavior

There are many options available to customize the look and feel of the client side code. You can even create your own theme. Look at our client API guide for more information on this topic.