我在我的 MVC 项目中实现 reCaptcha,如下所示。
    [HttpPost]
    [ValidateAntiForgeryToken]
    [RecaptchaControlMvc.CaptchaValidatorAttribute]
    public ActionResult Index(IndexTemp indextemp, bool captchaValid)
    {
        if (!captchaValid)
        {
            ModelState.AddModelError("", "You did not type the verification word correctly. Please try again.");
        }
        if (ModelState.IsValid)
        {
            // do stuff here
        }
    }
在 Web.config 我有以下内容。
<add key="ReCaptchaPrivateKey" value="some_key"/>
<add key="ReCaptchaPublicKey" value="another_key"/>
我从这里得到了 reCaptcha 。
我注意到 reCaptcha 并不总是按预期工作(即有时它会在输入的单词无效时进行验证)。经过一番测试,我注意到只要您正确输入了第一个单词,它将始终有效!
有任何想法吗?