I've implemented google's recapthca v2(checkbox) on my website(ASP.NET MVC) locally and, it works 100%. When I tried to copy over project files to my live website, the capthca did not work...
It does render correctly and I can interact with the checkbox, but the validation ALWAYS fails... It is the exact same project as on my localhost how can this be?
And I did change the site and secret keys when i moved files over to live site.
View:
<div class="g-recaptcha" data-sitekey="my_site_key"></div>
<div class="submit-frm-btn">
<button class="contact-btn bg-mediumBlue"
type="submit">
Submit
</button>
controller:
public ActionResult SaveForm(ContactUs contactUsForm)
{
//getting and setting response from captha
var response = Request["g-recaptcha-response"];
string secretkey = "my_secret_key";
var client = new WebClient();
var result = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret=" + secretkey + "&response=" + response +""));
var obj = JObject.Parse(result);
var status = (bool)obj.SelectToken("success");
ViewData["Message"] = status ? "Google reCaptcha validation success." : "Google reCaptcha validation failed.";
//status true = captcha successful
if (status)
{
if (ModelState.IsValid)
{
When captcha is correct and modelstate is valid, is save contact to DB. Note that this code works locally, I can successfully validate the capthca but the validation always fails on my live site.
Thanks for any help...