Demo: http://www.asp.net.vn/RecaptchaDemo.aspx
Để có thể sử dụng CAPTCHA bạn cần đăng ký 1 cặp keys:
1. Đăng ký tại: https://www.google.com/recaptcha/admin/create
2. Sau khi đăng ký xong, bạn sẽ nhận được kế quả:
Domain Name:
www.asp.net.vn This is a global key. It will work across all domains.
Public Key: 6Lco3AsAAAAAAO9g90AYGNg-vKC-0SvtU6bz
XXXX
Use this in the JavaScript code that is served to your users
Private Key: 6Lco3AsAAAAAAJaORp5DhQKjIbEZD_bJXhUq
XXXX Lưu ý: 4 ký tự sau mỗi cặp khóa đã thay bằng XXXX.
3. Sau đó, tham khảo ví dụ sau:
<%@ Page Language="C#" %>
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (recaptcha.IsValid)
{
lblResult.Text = "Bạn đã gõ đúng mã bảo vệ";
lblResult.ForeColor = System.Drawing.Color.Green;
}
else
{
lblResult.Text = "Bạn đã gõ sai mã bảo vệ";
lblResult.ForeColor = System.Drawing.Color.Red;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ASP.NET VIETNAM - CAPTCHA DEMO</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblResult" runat="server" />
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" PublicKey="6Lco3AsAAAAAAO9g90AYGNg-vKC-0SvtU6bzXXXX"
PrivateKey="6Lco3AsAAAAAAJaORp5DhQKjIbEZD_bJXhUqXX XX" />
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Test" OnClick="btnSubmit_Click" />
</div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>