INTRODUCTION
Google introduced a new tool for online users to keep their online properties safe and fine - reCAPTCHA - that you can easily add to your forum, registration form , blog, Online Payment Transaction, Internet Banking etc. Also, reCAPTCHA protects your site from spam.
How it works
Before information or Data posts back to the Server , GOOGLE reCAPTCHA asks online users some questions to avoid spam and abuse, and keeps your online sites safe.
GOOGLE reCAPTCHA Image Ref

Steps To complete this requirement
Step 1
First, create a basic type of MVC application named “SatyaLatestGoogleRecaptcha”.

Step 2
Check reference of Newtonsoft.Json in your "References" folder. Otherwise, you can install from NuGet Packages. This is nothing but a dll file “Newtonsoft.Json.dll”.

How to open NuGet to install
Right click on "References" folder and select "Manage NuGet Packages" and search for this Newtonsoft.Json.dll file and install.


Step 3
Add a Controller class file named “HomeController.cs”.
Code Ref
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Web;
- using System.Web.Mvc;
- using Newtonsoft.Json; //These two namespaces are required For Below mentioned class file WebClient and JObject.
- using Newtonsoft.Json.Linq;
- namespace SatyaLatestGoogleRecaptcha.Controllers {
- public class HomeController: Controller {
- //
- // GET: /Home/
- public ActionResult Index() {
- return View();
- }
- [HttpPost]
- public ActionResult Post() {
- var Yourresponse = Request["g-recaptcha-response"]; //Validate Google recaptcha here.
- string YoursecretKey = "Put Your Own Secret Key Here"; //Put Your Secret Key .
- var client = new WebClient();
- var result = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", YoursecretKey, Yourresponse)); //Pass your Response and Secret Key here.
- var obj = JObject.Parse(result); //Result In True or False.
- var humanstatus = (bool) obj.SelectToken("success");
- //check the status is true or not to identify you are a robot or not.
- if (humanstatus == true) //Condition put for message show based on True or false.
- {
- ViewBag.Notify = "SatyaPrakash's Google reCaptcha validated Successfully";
- } else {
- ViewBag.Notify = "SatyaPrakash's Google reCaptcha not validated Successfully";
- }
- //When you post form for save data , check both the model validation and google recaptcha validation.
- return View("Index"); // Here I used Index View.
- }
- }
- }
The above mentioned code is described with red highlighted Comment Line.

Step 4
Add a View cshtml file named “Index.cshtml” in "Views/Home" folder.
Code Ref
- @ {
- ViewBag.Title = "Satyaprakash Latest Google Recaptcha";
- } < h2 style = "color:red" > Satyaprakash Samantaray 's New Way For Robot Identification</h2> < fieldset > < legend style = "font-family:Arial Black;color:blue" > Test For Robot Identification < /legend> < div > @using(Html.BeginForm("Post", "Home", FormMethod.Post)) { < div class = "g-recaptcha"
- data - sitekey = "Put Your Own Site Key Here" > < /div>
- //As you created your own site key here.
- < input type = "submit"
- value = "Post"
- style = "color:Navy;font-family:Arial; font-size:large" / >
- } < /div>
- @if(ViewBag.Notify != null) //Put Some Javascript alert will show before show your status of Your reCAPTCHA is executed successfully or not.
- { < script type = "text/javascript" > alert("Click Ok To See Your Status !"); < /script>
- } < span style = "display:block; font-size:20px;color:green" >
- //Viewbag message comes from HomeController.cs file
- if (humanstatus == true) {
- ViewBag.Notify = "SatyaPrakash's Google reCaptcha validated Successfully";
- }
- else {
- ViewBag.Notify = "SatyaPrakash's Google reCaptcha not validated Successfully";
- } //
- @ViewBag.Notify < /span> < /fieldset> < script src = 'https://www.google.com/recaptcha/api.js'
- type = "text/javascript" > < /script>
- //This javascript file should be added for to access this reCAPTCHA api.























Satyaprakash SamantarayPosted Jun 12, 2018, 9:28 AM
make sure your configuration should be correct?
Akhil JimmyPosted Jun 12, 2018, 9:22 AM
Why my human status is always returning false?