將 reCAPTCHA 與 ASP.NET 搭配使用
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
重要事項:系統已不再支援 reCAPTCHA API 1.0 版,請升級至 2.0 版。瞭解詳情
reCAPTCHA ASP.NET 程式庫可讓您輕鬆
在 ASP.NET 網站上啟用 CAPTCHA,協助阻擋機器人
防範濫用行為程式庫已納入 reCAPTCHA API。
您可以使用任何 .NET 語言的程式庫,包括 C# 和 Visual Basic .NET。
如要搭配 ASP.NET 使用 reCAPTCHA,請下載 reCAPTCHA
ASP.NET 程式庫。
快速入門
註冊 API 金鑰後,請參考下列基本安裝操作說明
reCAPTCHA 支援 ASP.NET 的網站:
- 將網站的參考資料新增至 Library/bin/Release/Recaptcha.dll:在 Visual Studio 上
在網站選單中,選擇 [新增參考資料],然後按一下對話方塊中的 [.NET] 標籤。選取
Recaptcha.dll 元件 (位於 .NET 元件清單),然後按一下 [確定]。如果沒有看到
該元件,按一下 [瀏覽] 標籤,然後在硬碟上尋找組件檔案。
- 新增下列程式碼片段,將 reCAPTCHA 控制項插入要保護的表單:
將下列程式碼插入分頁上方:
<%@ 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>
其他資訊
自訂外觀和風格
提示和規範
疑難排解
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間: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"]],["上次更新時間: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"]]