我正在尝试按照此帖子的第三个到最顶层答案How to implement reCaptcha for ASP.NET MVC?上的说明,在我的MVC
ASP.net 项目上实施Googles reCaptcha。目前我已经下载并包含了正确的依赖项
using reCAPTCHA.MVC;
我的登录方法如下:
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
[CaptchaValidator(
PrivateKey = "your private reCaptcha Google Key",
ErrorMessage = "Invalid input captcha.",
RequiredMessage = "The captcha field is required.")]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
}
在我看来,我在我的内容中添加了验证码:
@html.beginform(){
@Html.Recaptcha()
@Html.ValidationMessage("ReCaptcha")
}
我还将公钥和私钥添加到我的web.config
文件中。
但是,当我在登录页面上运行所有内容时,captcha
框会显示,但没有点击的位置,我得到了error
:
“网站所有者的错误:无效的网站密钥”,其中要在验证码框中点击的框应为。
另外我试图重置按键但仍然没有运气。
答案 0 :(得分:0)
您可以在Controller中获得响应
var response =请求[&#34; g-recaptcha-response&#34;];
你可以轻松实现reCaptcha我在搜索中找到了一个例子,我希望这有帮助
https://www.codeproject.com/articles/874150/google-recaptcha-in-asp-net-mvc