locked
Google Recaptcha in ASP.net 4.7.2 RRS feed

  • Question

  • User351619809 posted

    I am trying to install Recaptcha in my project. In order to accomplish that, I downloaded

     recaptcha-dotnet-1.0.5.0-binary.zip 

    from here

    https://code.google.com/archive/p/recaptcha/downloads

    I unzipped the zip file and placed the Recpatcha in my project references:

    I added Recaptcha in my asp.net page like so:

    I put the below tag in my asp.net web form

      <%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>

    then I added the code in my aspx page like so:

    <form id="form1" runat="server">
            <div>
    
              <recaptcha:RecaptchaControl
                  ID="recaptcha"
                  runat="server"
                  Theme="red"
                  PublicKey="xxxx"
                  PrivateKey="xxxxx"
                  />
    
              <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" style="height: 26px" />
            </div>
        </form>

    when I run the asp.net application by pressing F5. I don't see anything on my web page except the submit button:

    I am not sure what am I doing wrong and how can I see Recaptcha.

    Any help will be highly appreciated.

    </div> </div>

    Tuesday, June 16, 2020 8:00 AM

Answers

  • User-719153870 posted

    Hi anjaliagarwal5,

    I tried the same process and this issue can be reproduced whether it is in V2 or V3.

    In my situation, press F12 to open the browser devtools, find the api call with the site key returns 404:



    Not sure what caused this problem, maybe you can check whether you are experiencing the same situation.

    Further investigation found that, check the Elements in devtools, the recaptcha:RecaptchaControl control seems be rendered to scripts:

    If this is the case, then i think it would be better to choose the JS library instead. Both reCAPTCHA v2 and reCAPTCHA v3 can perfectly work in my test. You will find the widget generated successfully.

    V2:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="https://www.google.com/recaptcha/api.js"></script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <div class="g-recaptcha" data-sitekey="******{your_sitekey}******"></div>
          <br/>
            </div>
        </form>
    </body>
    </html>

    V3:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="https://www.google.com/recaptcha/api.js"></script>
        <script>
    
            function onSubmit(token) {
                document.getElementById("form1").submit();
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <button class="g-recaptcha" 
            data-sitekey="*****{your_sitekey}******" 
            data-callback='onSubmit' 
            data-action='submit'>Submit</button>
            </div>
        </form>
    </body>
    </html>
    

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 17, 2020 3:02 AM

All replies

  • User1738843376 posted

    Hi,

    I've never used this implementation of Google ReCaptcha before. Have been using the JS library for v2.

    Nonetheless, I'm guessing this implementation uses v3, which produces no visible recaptcha as we're traditionally used to see around the web. Instead, if captures inputs from you mouse movements to determine if you're a human or not. This might be why you're getting no visible result. 

    It might also be due to the lack of page validation being called inside the sub associated with the button, testing its result, and having a literal control for instance, added to your page to return different messages according to the result of the validation.

    You can try to refer to the following URL for a better understanding:

    https://developers.google.com/recaptcha/old/docs/aspnet

    Hope i was able to provide you with some help

    Wednesday, June 17, 2020 1:55 AM
  • User-719153870 posted

    Hi anjaliagarwal5,

    I tried the same process and this issue can be reproduced whether it is in V2 or V3.

    In my situation, press F12 to open the browser devtools, find the api call with the site key returns 404:



    Not sure what caused this problem, maybe you can check whether you are experiencing the same situation.

    Further investigation found that, check the Elements in devtools, the recaptcha:RecaptchaControl control seems be rendered to scripts:

    If this is the case, then i think it would be better to choose the JS library instead. Both reCAPTCHA v2 and reCAPTCHA v3 can perfectly work in my test. You will find the widget generated successfully.

    V2:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="https://www.google.com/recaptcha/api.js"></script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <div class="g-recaptcha" data-sitekey="******{your_sitekey}******"></div>
          <br/>
            </div>
        </form>
    </body>
    </html>

    V3:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="https://www.google.com/recaptcha/api.js"></script>
        <script>
    
            function onSubmit(token) {
                document.getElementById("form1").submit();
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <button class="g-recaptcha" 
            data-sitekey="*****{your_sitekey}******" 
            data-callback='onSubmit' 
            data-action='submit'>Submit</button>
            </div>
        </form>
    </body>
    </html>
    

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 17, 2020 3:02 AM
  • User351619809 posted

    Are you putting data-secret key too or just data-sitekey?

    Thursday, June 18, 2020 3:59 PM