reCaptcha implementation example for Razor Pages

robs23 96 Reputation points
2021-07-27T13:59:05.13+00:00

Hello,

Just a quick question: can someone support me with example on how to implement reCaptcha verification in Razor Pages? I mean specifically Razor Pages, not MVC. Unfortunately, due to unfortunate naming (razor pages are also part of Asp.net MVC setup) I'm getting all the examples for MVC and they don't work for me.. I wish Microsoft would change the confusing name, but I'm guessing it's off the table now..
I've been trying to implement it with this plugin but the captcha isn't displayed (I get only captcha sign in the right corner saying that the site is protected, but still can submit form without any captcha validation).. The answer doesn't have to use the plugin, any working solution is welcome! :)

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,281 questions
{count} votes

Accepted answer
  1. robs23 96 Reputation points
    2021-08-01T13:27:29.777+00:00

    With a help of packet's author I figured out that no "I'm not a robot" chekckbox appears by the design of V3 captchas - their only indication is the badge and no additional task for a user to prove he's not a robot is needed..

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. robs23 96 Reputation points
    2021-07-29T13:12:11.343+00:00

    @AgaveJoe , can't publish "reply" to your answer for some reason, so I'm posting it as separate answer..

    Thanks, I must have overlooked that.. Honestly speaking I had it mostly like this, added necessary changes, but result is still the same - no "captcha" element is visiable on the page to tick "I'm not a robot" checkbox.. When I inspect it in Chrome's dev tools I can see some element has been generated:

    <div class="form-group">  
    <input id="g-recaptcha-response" name="g-recaptcha-response" type="hidden" value="03AGdBq25La3sDHMHZvQjvAKHnUg720REb_GnVxuhh6FKU4TeYwgcjdNxsKJA1CY8fw6hdSprySH_23Cy-ryX0I-aJTpUfnCKPq8E6jpsQ5x7_jvTjId4OQoFMAj3FtNLYD9wB3znlI2AMs59bp5U9xg_3tsA8Nv_UZCn_TFUxYqKuaomxes6p9bAjCimoQ63o2AXA2ubqaNGFNsvxOz4I84wMGbfyM5PT0_7DIIgJXGo1t1itnYvGGYifLahgRO6-0_knnxzZUfktb2UB5nxK9YYmBBmJE0XiVJV7P9MHoKHagwOVn8nkhFqDHNt3H5opMIHADe0uUyWNc5Olv3abkq8h7grPul2nf3W52ryRS5GkCCjg20NRRKm0hzD4Kt-F2Lkym5QXv5PveLiW3w5vxtA4fUj8dEgdxRJ02S-04FS0u4ggwDtMhLNKxyLQfbunotPzv6HBZqXm"><script src="https://www.google.com/recaptcha/api.js?render=6LdxXcMbAAAAAH2wQWM7E1CUW1M7tPHTnu2s3GCK&amp;hl=en"></script><script>function updateReCaptcha() {grecaptcha.execute('6LdxXcMbAAAAAH2wQWM7E1CUW1M7tPHTnu2s3GCK', {action: 'homepage'}).then(function(token){document.getElementById('g-recaptcha-response').value = token;});}grecaptcha.ready(function() {setInterval(updateReCaptcha, 100000); updateReCaptcha()});</script>  
                    </div>  
    

    but for some reason I cannot see it on the page :( Perhaps you'd like to check it yourself - here's the page and here's its source code.

    0 comments No comments