This post shows how to implement google recaptcha in ASP.NET MVC using c-sharp code.

To integrate Google reCAPTCHA V2 in your websites, you need to go to Google reCaptcha website, then login with your google account.

Next, Choose the reCAPTCHA v2 option, then add your domain in the list of domains

implement google recaptcha in mvc

Click Register button, You will get a site key and a secret key.

Open your Manage Nuget Packages, then install ReCaptcha-AspNet or you can install from Nuget command line

Install-Package ReCaptcha-AspNet

Open your web.config under the appSettings section, add your secret and public keys as the following.

<add key="recaptcha-public-key" value="Your public key" />
<add key="recaptcha-private-key" value="Your private key" />

Open your html layout, then modify your code as shown below

    <input type="submit">

Create a test action in your home controller

public ActionResult Test() {

    string captchaResponse = Request.Form["g-recaptcha-response"];
    if (ReCaptcha.ValidateCaptcha(captchaResponse)) {
        return View();
    // A Bot
    return RedirectToAction("Robot");

and don't forget include the following namespace

using hbehr.recaptcha;