无法为 ASP.net 升级过时的 Google ReCAPTCHA 版本 1

Can't upgrade Outdated Google ReCAPTCHA version 1 for ASP.net

我们目前使用的是 reCAPTCHA 版本 1,但遇到了该错误(reCAPTCHA V1 已关闭)。

我们目前正在为 ASP.Net 使用 Recaptcha.dll(产品版本 1.0.0.0)。
如何将其更新到当前版本。他们的下载页面中没有更新版本的dll。

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

我们目前在标签内使用普通的 reCAPTCHA 控件。

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

<recaptcha:RecaptchaControl
ID="recaptcha"
runat="server"
PublicKey="your_public_key"
PrivateKey="your_private_key"
/>

从版本 2 开始,asp.net 网络表单没有定制的 Nuget 包或库。您必须使用文档中列出的方法并迁移到版本 2,更好的是 v3。

因此,请转到位于 google 的管理面板,获取新库,然后您所要做的就是向您的页面添加一些 html 标记:

<body>
    <form action="/" method="POST">
        <div class="g-recaptcha" data-sitekey="xxxx-xxxx-xxxx-xxxx"></div>
        <input type="submit" value="Submit">
    </form>

    <script src="https://www.google.com/recaptcha/api.js" async defer></script>
</body>

对于 v3,它看起来像这样:

<script src="https://www.google.com/recaptcha/api.js?render=xxxx-xxxx-xxxx-xxxx"></script>
<script>
    grecaptcha.ready(function() {
    grecaptcha.execute('xxxx-xxxx-xxxx-xxxx', {action: 'homepage'}).then(function(token) {
         ...
    });
});
</script>

用您的特定密钥替换数据站点密钥 属性,您应该已经 运行 了。

v2 参考:https://developers.google.com/recaptcha/docs/display

v3 参考:https://developers.google.com/recaptcha/docs/v3