将 reCAPTCHA 与 ASP.NET 搭配使用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
重要提示:1.0 版 reCAPTCHA API 不再受支持,请升级到 2.0 版。了解详情
reCAPTCHA ASP.NET 库提供了一种将
ASP.NET 网站上的人机识别系统,有助于阻止漫游器
滥用该限制。该库封装了 reCAPTCHA API。
您可以使用任何 .NET 语言(包括 C# 和 Visual Basic .NET)的库。
要将 reCAPTCHA 与 ASP.NET 配合使用,您可以下载 reCAPTCHA
ASP.NET 库相同。
快速入门
在您注册 API 密钥后,以下是安装 API 密钥的基本说明
使用 ASP.NET 在您的网站上使用 reCAPTCHA:
- 在网站上添加对 library/bin/Release/Recaptcha.dll 的引用:在 Visual Studio 中
在“Website”菜单中,选择“Add Reference”,然后点击对话框中的 .NET 标签。选择
从 .NET 组件列表中选中 Recaptcha.dll 组件,然后点击“确定”。如果没有看到
点击“浏览”标签,然后在硬盘上找到汇编文件。
- 添加以下代码段,将 reCAPTCHA 控件插入您希望保护的表单中:
在 aspx 页面的顶部插入以下代码:
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
然后将 reCAPTCHA 控件插入到 <form runat="server">代码中:
<recaptcha:RecaptchaControl
ID="recaptcha"
runat="server"
PublicKey="your_public_key"
PrivateKey="your_private_key"
/>
您需要将公钥和私钥分别替换为 PublicKey 和 PrivateKey。
- 确保使用 ASP.NET 验证来验证表单(提交时应检查 Page.IsValid)。
以下代码是一个“Hello World”与 reCAPTCHA 进行集成。C# 示例是
包含在库下载内容中
<%@ 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>
延伸阅读
自定义外观和风格
提示和准则
问题排查
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-25。"],[[["reCAPTCHA ASP.NET library offers a straightforward way to integrate CAPTCHA into your ASP.NET website to prevent bot abuse."],["Version 1.0 of the reCAPTCHA API is no longer supported; users should upgrade to Version 2.0."],["The library supports various .NET languages, including C# and Visual Basic .NET, and requires adding a reference to Recaptcha.dll in your project."],["To 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."],["Basic installation instructions and a \"Hello World\" example in Visual Basic are provided to guide users through the integration process."]]],["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"]]