ReCaptcha and MVC3, problems getting Microsoft.Web.Helpers working

流过昼夜 提交于 2019-12-04 17:09:40

Here's a step by step guide:

  1. Create a new ASP.NET MVC 3 project using the default template
  2. Install the microsoft-web-helpers NuGet
  3. In the Index.cshtml view of HomeController create a form and bring the Microsoft.Web.Helpers namespace into scope:

    @using Microsoft.Web.Helpers
    
    @using (Html.BeginForm())
    {
        @ReCaptcha.GetHtml(publicKey: "__ put your public key here __")
        <button type="submit">OK</button>
    }
    
  4. And to validate the Captcha in the controller:

    [HttpPost]
    public ActionResult Index(MyViewModel model)
    {
        if (!ReCaptcha.Validate(privateKey: "__ put your private key here __"))
        {
            return View(model);
        }
        return RedirectToAction("success");
    }
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!