web analytics

How to validate ReCAPTCHA.

There are some cases when a user want to validate a CAPTCHA and perform some activity on its results. ReCAPTCHA gives an .NET API to perform some operations on its CAPTCHA component. Following is the code to validate a CAPTCHA on server side.

ASPX Markup:

<!– Start ReCAPTCHA –>
<span class="orangetext">Captcha Verification:</span>
PublicKey = Public Key
PrivateKey=Private Key
Theme="blackglass" />
<!– End ReCAPTCHA –>


String challenge = Request["recaptcha_challenge_field"];
String reponseField = Request["recaptcha_response_field"];
String privateKey = "6LeptwEAAAAAAAQkSaGs-eb5ak6UaJrFUBLcRlKO";

Recaptcha.RecaptchaValidator abc = new Recaptcha.RecaptchaValidator();
abc.Challenge = challenge;
abc.PrivateKey = privateKey;
abc.RemoteIP = Request.ServerVariables["REMOTE_ADDR"];
abc.Response = reponseField;

Recaptcha.RecaptchaResponse resp = abc.Validate();

if (!resp.IsValid)
Response.Write("<pPlease input correct verification code!</p>");

7 thoughts on “How to validate ReCAPTCHA.

  • February 23, 2010 at 12:33 pm

    Where do I put the code to validate the re-captcha? I already have a form that submits a new account but I am not sure where or how to add the second part labeled “code:”

  • February 23, 2010 at 9:35 pm

    Add that validation code, in code behind of the page in submission logic of webpage.

  • February 24, 2010 at 9:10 am

    Just copy/paste that code into my form? Can we take this offline maybe? I can email you my code if you are willing to help.


  • February 24, 2010 at 10:15 am

    hmm.. can you elaborate what type of exception/issue you are getting…

    have you included Recaptcha reference in your code ?

  • February 24, 2010 at 1:22 pm


    Basically I have a registration form that when I include the first part of the code and hit ‘join’ I get an error, it seems as though the reCAPTCHA is interferring with another module which emails me when a new account is created.

    This is the message I get:
    User Agent:
    Path: as HTTP
    Message: Error occurred while running background task PokeSite
    System.Exception: No CSContext exists in the Current Application. AutoCreate fails since HttpContext.Current is not accessible.
    at CommunityServer.Components.CSContext.get_Current()
    at JeffDavis.CS.Modules.PokeSite.Execute(XmlNode prefNode)
    at Telligent.Tasks.Task.ExecuteTask()

  • February 24, 2010 at 1:40 pm

    I turned that off and I still get an error message. It appears that the page wont allow you to click ‘join’ without entering the recaptcha, and when you do it redirects me to a default error page (basic communityserver message) but nothing showing in the logs as to what the problem is.

    I am stuck.

    This is what I have far as reCAPTCHA in my form (wont post the entire thing, way too long):

    That’s it.

Leave a Reply

%d bloggers like this: