reCaptcha
https://www.google.com/recaptcha/admin/create

v2 or v3
Choose whether you want to use v2 or v3.
• You will be given the following two keys:
• Site Key (for the client side)
• Secret Key (for the server side)
public class HomeController : Controller
{
private const string SecretKey = "YOUR_SECRET_KEY";
[HttpPost]
public async Task<IActionResult> Submit(string name, string email, string message, string g_recaptcha_response)
{
var httpClient = new HttpClient();
var response = await httpClient.PostAsync(
$"https://www.google.com/recaptcha/api/siteverify?secret={SecretKey}&response={g_recaptcha_response}",
null);
var jsonString = await response.Content.ReadAsStringAsync();
dynamic result = JsonConvert.DeserializeObject(jsonString);
if (result.success == "true")
{
return Content("Form success!");
}
else
{
return Content("Please perform reCAPTCHA verification.");
}
}
}
Design
<form action="/Home/Submit" method="post">
<input type="text" name="name" placeholder="Name" required />
<div class="g-recaptcha" data-sitekey="YOUR_SITE_KEY"></div>
<button type="submit">Gönder</button>
</form>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<form action="/Home/Submit" method="post">
<input type="text" name="name" placeholder="Name" required />
<div class="g-recaptcha" data-sitekey="YOUR_SITE_KEY"></div>
<button type="submit">Gönder</button>
</form>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>