I want add captcha in login view for my ASP.NET application. The view is quite simple has only email and password text box. Now below the email and password text box I want to add captcha in my login form.
I have look into many articles about adding captcha and found Captcha in ASP.NET MVC 5 is quite simple to use but when I added it to my app.
Instead of showing captcha image it starts displaying a cross symbol.
I have checked all the configuration already there is nothing wrong with the implementation. Is there any other easiest way to add captcha in ASP.NET app ?
2
Answers
Hey Thanks everyone for the suggestions. So the cross symbol was occurred due to the security header named referrer-policy in web.config. When i removedthis header. Captcha was successfully displayed jn my app.
Below is the full implementation from one of my latest projects – it simply follows Google’s Recaptcha guidance with some additional useful code – please check the latest Google documentation for the latest updates:
Add 2 new keys in your web.config file – one for the site key and the other for the secret key – you get these values when you register your website from the Google Recaptcha portal.
Create a public static Config class to reach your web.config key values easily as follows;
Add the g-recaptcha section to your view, i.e.
Script section on the same view;
Add RecaptchaToken to your viewmodel;
And here is your post action and how you can validate your recapcha token and add some custom validation errors:
StringExtension to validate the recapcha token:
This is how things look like: