Recaptcha asp.net quickstart
These instructions should get you started quickly.
- Download the reCAPTCHA Library.
- Add a reference to library/bin/Release/Recaptcha.dll to your website
- Insert the reCAPTCHA control into the form you wish to protect. At the top of the aspx page, insert the following code:
4. <%@ 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=""
>
- If you haven't done so, sign up for an API key. Put the public and private key in the PublicKey and PrivateKey properties
- 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 C# :
<%@ Page Language="cs" %>
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
<script runat=server>
Protected void btnSubmit_Click(object sender, EventArgs e)
If( Page.IsValid)
{
lblResult.Text = "You Got It!";
lblResult.ForeColor = System.Drawing.Color.Green;
}
else
{
lblResult.Text = "Incorrect";
lblResult.ForeColor = System.Drawing.Color.Red;
}
</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>
No comments:
Post a Comment