Using reCAPTCHA with ASP.NET
Stay organized with collections
Save and categorize content based on your preferences.
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.
Quick Start
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>
Further Reading
Customizing Look and Feel
Tips and Guidelines
Troubleshooting
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003ereCAPTCHA ASP.NET library offers a straightforward way to integrate CAPTCHA into your ASP.NET website to prevent bot abuse.\u003c/p\u003e\n"],["\u003cp\u003eVersion 1.0 of the reCAPTCHA API is no longer supported; users should upgrade to Version 2.0.\u003c/p\u003e\n"],["\u003cp\u003eThe library supports various .NET languages, including C# and Visual Basic .NET, and requires adding a reference to Recaptcha.dll in your project.\u003c/p\u003e\n"],["\u003cp\u003eTo implement reCAPTCHA, you need to insert specific code snippets, including a registration tag and the reCAPTCHA control with your API keys within your ASP.NET form.\u003c/p\u003e\n"],["\u003cp\u003eBasic installation instructions and a "Hello World" example in Visual Basic are provided to guide users through the integration process.\u003c/p\u003e\n"]]],["The document details integrating reCAPTCHA into ASP.NET websites using the ASP.NET library. Key actions include: adding a reference to `Recaptcha.dll` in Visual Studio, registering the reCAPTCHA control using a tag prefix, and inserting the control within the form, while substituting in personal API keys. You must ensure ASP.NET form validation is in place by checking `Page.IsValid`. It also notes that reCAPTCHA version 1.0 is outdated, urging an upgrade to version 2.0.\n"],null,["# Using reCAPTCHA with ASP.NET\n\n**Important** : Version 1.0 of the reCAPTCHA API is no longer supported, please upgrade to Version 2.0. [Learn more](/recaptcha/docs/faq)\n\nThe reCAPTCHA ASP.NET Library provides a simple way to place a\n[CAPTCHA](http://www.google.com/recaptcha/) on your ASP.NET website, helping you stop bots\nfrom abusing it. The library wraps the [reCAPTCHA API](/recaptcha/old/intro).\nYou can use the library from any .NET language including C# and Visual Basic .NET.\n\nTo use reCAPTCHA with ASP.NET, you can download the [reCAPTCHA\nASP.NET library](http://code.google.com/p/recaptcha/downloads/list?q=label:aspnetlib-Latest).\n\nQuick Start\n-----------\n\nAfter you've signed up for your API keys, below are basic instructions for installing\nreCAPTCHA on your site with ASP.NET:\n\n1. 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.\n2. 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:\n\n ```matlab\n \u003c%@ Register TagPrefix=\"recaptcha\" Namespace=\"Recaptcha\" Assembly=\"Recaptcha\" %\u003e\n ```\n\n Then insert the reCAPTCHA control inside of the \\\u003cform runat=\"server\"\\\u003e tag: \n\n ```scdoc\n \u003crecaptcha:RecaptchaControl\n ID=\"recaptcha\"\n runat=\"server\"\n PublicKey=\"your_public_key\"\n PrivateKey=\"your_private_key\"\n /\u003e\n ```\n\n You will need to substitute your public and private key into PublicKey and PrivateKey respectively.\n3. Make sure you use ASP.NET validation to validate your form (you should check Page.IsValid on submission).\n\nThe following is a \"Hello World\" with reCAPTCHA using Visual Basic. A C# sample is\nincluded with the library download. \n\n```matlab\n \u003c%@ Page Language=\"VB\" %\u003e\n \u003c%@ Register TagPrefix=\"recaptcha\" Namespace=\"Recaptcha\" Assembly=\"Recaptcha\" %\u003e\n \u003cscript runat=server%gt;\n Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)\n If Page.IsValid Then\n lblResult.Text = \"You Got It!\"\n lblResult.ForeColor = Drawing.Color.Green\n Else\n lblResult.Text = \"Incorrect\"\n lblResult.ForeColor = Drawing.Color.Red\n End If\n End Sub\n \u003c/script\u003e\n \u003chtml\u003e\n \u003cbody\u003e\n \u003cform runat=\"server\"\u003e\n \u003casp:Label Visible=false ID=\"lblResult\" runat=\"server\" /\u003e\n \u003crecaptcha:RecaptchaControl\n ID=\"recaptcha\"\n runat=\"server\"\n Theme=\"red\"\n PublicKey=\"your_public_key\"\n PrivateKey=\"your_private_key\"\n /\u003e\n\n \u003casp:Button ID=\"btnSubmit\" runat=\"server\" Text=\"Submit\" OnClick=\"btnSubmit_Click\" /\u003e\n \u003c/form\u003e\n \u003c/body\u003e\n \u003c/html\u003e\n```\n\n### Further Reading\n\n- [Customizing Look and Feel](/recaptcha/old/docs/customization)\n- [Tips and Guidelines](/recaptcha/old/docs/tips)\n- [Troubleshooting](/recaptcha/old/docs/troubleshooting)"]]