ASP.NET Core hCaptcha Component for Server-Side Blazor.
PM> Install-Package Texnomic.Blazor.hCaptcha
-
Reference hCaptcha & NuGet Package JavaScript Files In
Pages/_Host.cshtml
File:<head> <script src="https://hcaptcha.com/1/api.js&render=explicit" async type="text/javascript"></script> <script src="_content/Texnomic.Blazor.hCaptcha/scripts/hCaptcha.js" type="text/javascript"></script> </head>
-
Add Package Configuration To Dependancy Injection Services in
Startup.cs
File:using Texnomic.Blazor.hCaptcha.Extensions; public void ConfigureServices(IServiceCollection Services) { Services.AddHttpClient(); Services.AddHCaptcha(Options => { Options.SiteKey = "10000000-ffff-ffff-ffff-000000000001"; Options.Secret = "0x0000000000000000000000000000000000000000"; }); }
-
Create Callback Function & Backing Field To Capture Captcha Result In
Example.razor.cs
File:private bool IsCaptchaValid { get; set; } protected void hCaptchaCallback(bool Result) => IsCaptchaValid = Result;
-
Finally, Drop-In hCaptcha Component & Bind Callback Function In
Example.razor
File:<HCaptcha Callback="hCaptchaCallback" Theme="Theme.Dark"></HCaptcha>