Created
December 13, 2020 12:33
-
-
Save villian/bc18f546306eea4b16dccdcc402c0318 to your computer and use it in GitHub Desktop.
c# mvc Recaptcha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
[ValidateAntiForgeryToken] | |
public ActionResult Contact(ContactModel model) | |
{ | |
var response = Request["g-recaptcha-response"]; | |
string secretKey = ""; // Ur secretKey | |
var webClient = new WebClient(); | |
var result = webClient.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secretKey, response)); | |
var obj = JObject.Parse(result); | |
var status = (bool)obj.SelectToken("success"); | |
if (ModelState.IsValid && status == true) | |
{ | |
//Ur code to send message | |
TempData["ContactSuccess"] = "success"; | |
} | |
// redirect | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="col-md-12"> | |
<div class="g-recaptcha" data-sitekey=""></div> | |
</div> | |
<script src="https://www.google.com/recaptcha/api.js" ></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment