如何使用验证码在asp.net mvc的 [英] How to Use Captcha in asp.net mvc

查看:153
本文介绍了如何使用验证码在asp.net mvc的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何一个可以告诉我如何使用asp.net的MVC验证码?
有没有需要下载任何控制呢?


解决方案

希望能还不算晚把我的两分钱中...

介绍的 MvcReCaptcha

我想实现我的第一个ASP.NET MVC网站CAPTCHA验证当面对这个确切同样的问题。发现许多库后,我发现了似乎(而且似乎仍然)是最简单高效图书馆:的 MvcReCaptcha 从那时起,我已经使用这个库,我所有的ASP.NET MVC的网站。

在实施后的 MvcReCaptcha 的,它会产生安全上的视图CAPTCHA并提供验证是否成功的行动布尔值。


使用说明

下面是如何下载和引用后实现它的 MvcReCaptcha 的从您的项目DLL(从复制的指令的 MvcReCaptcha 的主页):


  

使用验证码的ASP.NET MVC:


  
  


  现在非常容易安装的reCAPTCHA
  在你的Asp.Net MVC网站。


  
  

对于注册验证码,
   http://recaptcha.net/whyrecaptcha.html


  
  

如何使用


  
  

第1步:添加您的公共和私人
  关键在你的web.config文件
  的AppSettings节

 <&的appSettings GT;
  <添加键=ReCaptchaPrivateKeyVALUE = - PRIVATE_KEY - />
  <添加键=ReCaptchaPublicKeyVALUE = - 公钥 - />
< /的appSettings>


  
  

第2步:添加新的命名空间到你
  web.config中

 <&命名空间GT;
  <添加命名空间=MvcReCaptcha.Helpers/>
< /命名空间>


  
  

第3步:实现在你的逻辑
  查看实际呈现的验证码
  控制

 <%= Html.GenerateCaptcha()%GT;


  
  

第四步:实施控制器
  将处理表单动作
  提交和验证码验证

  [CaptchaValidator]
的[AcceptVerbs(HttpVerbs.Post)
公众的ActionResult CreateComment(的Int32 ID,布尔captchaValid)
{
  如果(!captchaValid)
  {
      ModelState.AddModelError(_表,你没有输入正确的验证字,请再试一次。);
  }
  其他
  {
      //如果我们走到这一步,事情失败了,重新显示形式
      返回查看();
  }
}


祝你好运!

can any one tell me how to use captcha in asp.net mvc? is there any need to download any control for it?

解决方案

Hoping it's not too late to put my two cents in...

Introducing MvcReCaptcha

I faced this exact same issue when trying to implement CAPTCHA validation on my first ASP.NET MVC site. After discovering many libraries, I found what seemed (and still seems) to be the most straightforward and efficient library: MvcReCaptcha. Since then, I have used this library for all of my ASP.NET MVC sites.

After you implement MvcReCaptcha, it securely generates a CAPTCHA on your view and provides a boolean value of whether the validation was successful to the action.


Instructions for Use

Here's how to implement it after downloading and referencing the MvcReCaptcha DLL from your project (instructions copied from MvcReCaptcha home page):

Using ReCaptcha with ASP.NET MVC:

It is now extremely easy to setup ReCaptcha on your Asp.Net MVC Website.

Signup for reCaptcha, http://recaptcha.net/whyrecaptcha.html

How to Use:

Step 1: Add your Public and Private key to your web.config file in appsettings section

<appSettings>
  <add key="ReCaptchaPrivateKey" value=" -- PRIVATE_KEY -- " />
  <add key="ReCaptchaPublicKey" value=" -- PUBLIC KEY -- " />
</appSettings>    

Step 2: Add new namespace to your web.config

<namespaces>
  <add namespace="MvcReCaptcha.Helpers"/>
</namespaces>

Step 3: Implement the logic in your view to actually render the Captcha control

<%= Html.GenerateCaptcha() %>

Step 4: Implement the Controller Action that will handle the form submission and Captcha validation

[CaptchaValidator]
[AcceptVerbs( HttpVerbs.Post )]
public ActionResult CreateComment( Int32 id, bool captchaValid )
{
  if (!captchaValid)
  {
      ModelState.AddModelError("_FORM", "You did not type the verification word correctly. Please try again.");
  }
  else
  {
      // If we got this far, something failed, redisplay form
      return View();
  }
}

Good luck!

这篇关于如何使用验证码在asp.net mvc的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆