2.1, 2.2
>> Install-Package App.Infra.Integration.ReCaptcha
or
>> dotnet add package App.Infra.Integration.ReCaptcha
[ReCaptcha]
[ReCaptchaIgnore]
Is Taghelper must be inserted inside the <form>
in .cshtml
files.
@Html.ReCaptcha()
To configure the reCAPTCHA you must by this code snippet with your key information, in the file Startup.cs
services
.AddMvc(options => {
options.Filters.Add(new ReCaptchaActionFilter( reCaptcha => {
reCaptcha.PublicKey = "you-public";
reCaptcha.SecretKey = "you-secret";
reCaptcha.Redirect = "/access/denied"; /Custom
}));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
This support package for the reCAPTCHA to validate all Methodos, the more we encourage only use in calls POST, PUT, DELETE
Although the GET
works.
[ReCaptcha]
public class ExampleController : Controller
{
[HttpGet]
public IActionResult Index()
{
//...
}
[HttpGet]
public IActionResult Index(object obj)
{
//...
}
}
[ReCaptcha]
public class ExampleController : Controller
{
[HttpGet]
[ReCaptchaIgnore]
public IActionResult Index()
{
//...
}
[HttpPost]
public IActionResult Index(object obj)
{
//...
}
}
public class ExampleController : Controller
{
[HttpGet]
public IActionResult Index()
{
//...
}
[HttpPost]
[ReCaptcha]
public IActionResult Index(object obj)
{
//...
}
}
<form asp-route="YouRoute" method="post">
@Html.ReCaptcha()
</form>