ModelState.isValid is always false in Login.html.cs after setting Google reCAPTCHA.

Volk Volk 551 Reputation points
2024-01-28T15:04:35.1533333+00:00

Hi! I set Google reCAPTCHA V3 to the Login form in Net.Core 6. Did everything as in this video. https://youtu.be/hfMiM6tRaQI?si=kknfnb0iJzwVFiOG The domains in the settings when receiving the keys were set by localhost and the site domain itself. But now I always see in Login.html.cs if(ModelState.isValid) = false in the public async Task<IActionResult> OnPostAsync() method. Can anyone tell me why this is so? Maybe someone has encountered such a problem? Thanks!

Developer technologies | ASP.NET | ASP.NET Core
Microsoft 365 and Office | Development | Office JavaScript API
{count} votes

3 answers

Sort by: Most helpful
  1. Volk Volk 551 Reputation points
    2024-02-01T14:51:48.84+00:00

    As I expected, Google ReCaptcha works (In my case) on the example of this video (I recommend).

    Google reCAPTCHA v3 Tutorial - .NET 6 Core - With Code In Description - Part 1: https://youtu.be/-0_qwxttEoI?si=qkJ7Cm9VKgdshfiV Google reCAPTCHA v3 Tutorial - .NET 6 Core - With Code In Description - Part 2: https://youtu.be/t-SVLZxC6CQ?si=2iB0LEKWsrZjP1qE

    The advice of those present where did not help me, but thank you all for the answers anyway.

    The issue is closed.

    1 person found this answer helpful.
    0 comments No comments

  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2024-01-29T17:08:05.6366667+00:00

    so did you add the javascript code to the view to fetch the recaptcha token, and include on the form submit?

    https://github.com/langer-jaroslav/GoogleReCaptcha.V3

    also check the browser console for any javascript errors.


  3. Zhiliang Xu 1 Reputation point Microsoft Employee
    2024-01-31T10:59:33.6766667+00:00

    this is a test answer……


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.