ReCaptcha and MVC3, problems getting Microsoft.Web

2019-04-14 06:32发布

I have reCaptcha installation problems. I already saw some posts about that, even in StackOverflow but it didn't help me to get it working.

I followed this post, and this post but in this line:

@using Microsoft.Web.Helpers

I get the message:

The type or namespace name 'Helpers' does not exist in the namespace 'Microsoft.Web' (are you missing an assembly reference?)

I added all references mentioned, all assemblies in both web.config files (root and view folder), restarted VS2010, updated the MVC3 package, included WebMatrix packages but I couldn't get it working.

I guess it should be simple to install, but I don't know what I'm doing wrong.

Anyone could help me?

1条回答
够拽才男人
2楼-- · 2019-04-14 06:49

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");
    }
    
查看更多
登录 后发表回答