我正在使用MvcCaptcha。 为此,我使用了这个参考 http://sameercode.wordpress.com/2013/01/08/mvc-captcha-using-dll/
http://captchamvc.codeplex.com/releases/view/103937
我按照所有步骤操作,但没有生成验证码图像。
请参阅附图
我是否必须添加任何配置设置..
应该出现的图片是
答案 0 :(得分:0)
对于此示例,我将使用MathCaptcha的实现。在Controller中你应该添加:
using CaptchaMvc.Attributes;
...
// At the action that process your form you have to add the [CaptchaVerify] atttribute
[HttpPost]
[CaptchaVerify("Captcha result is not valid.")] // Captcha is now able for validation
public ActionResult yourAction(FormCollection collection)
{
if (!ModelState.IsValid)
{
ViewBag.Error = "The captcha answer is not correct.";
return View("SameViewForm");
}
else
{
...
// Whatever you have to do when Captcha answer is correct.
return View();
}
}
在视图中:
// Add
@using CaptchaMvc.HtmlHelpers
...
@using (Html.BeginForm())
{
...
<label style="color: red">@ViewBag.Error</label>
@Html.MathCaptcha()
<input type="submit" value="Send" />
}