问题
I am trying to insert a captcha in my ASP.NET code. Basically, in the lbt_proceed_click()
method, I want the browser to proceed to the next page using Response.Redirect("foo")
only if the captcha entered is correct.
I searched, but could not find a solution, especially since I am not using a form to send data, but writing to a database directly, and then moving to the next page using Response.Redirect()
.
回答1:
- go to the reCAPTCHA site and register for a unique key
- Download reCAPTCHA .NET Library
- Create and Save your Public and Private keys safely
- In the website we add a reference to library/bin/Release/Recaptcha.dll
after the @Page directive, insert the following code:
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha"%>
add control in asp.net tag:
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" PublicKey="Your very own public key here" PrivateKey="Your very own privat key here" />
add button and label to your form
add the following button click method(btnSubmit_Click) in code behind file :
if (Page.IsValid) { lblResult.Text = "You Got It!"; // Or Use Response.redirect("foo"); } else { lblResult.Text = "Incorrect"; }
Test your Page!
来源:https://stackoverflow.com/questions/8443616/implementing-recaptcha-in-asp-net