Validates the Google ReCapture 2.
First go to https://www.google.com/recaptcha/admin and create a site and secret key. Include "localhost" for debugging.
On the Razor page add the following
@using Microsoft.Extensions.Configuration@inject IConfiguration config<div class="col-md-12"> <div class="g-recaptcha" data-sitekey="@(config.GetValue<string>("ReCaptcha:SiteKey"))"></div></div>@section Scripts { <script src="https://www.google.com/recaptcha/api.js"></script> <script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>}public IActionResult MyView(){ if (SiUtil.VerifyCaptcha(HttpContext, _config.GetValue<string>("ReCaptcha:SecretKey"))) { ... do your work }}