BotDetect MVC CAPTCHA Documentation

This page is an index of BotDetect Captcha documentation regarding MVC Captcha integration and validation, listing code examples, how to guides, the BotDetect MVC API reference and implementation options available in different versions of BotDetect and various supported MVC frameworks.

MVC CAPTCHA in ASP.NET

ASP.NET MVC CAPTCHA Integration How To Guide

BotDetect ASP.NET Captcha protection can be added to your ASP.NET MVC applications using the MvcCaptcha class, a BotDetect HtmlHelper and a custom ActionFilterAttribute implemented in the BotDetect.Web.Mvc.dll assembly.

  1. Display a Captcha challenge on the Asp.Net MVC View
  2. Check is the visitor a human in the Controller action

ASP.NET MVC Basic CAPTCHA Example

The ASP.NET MVC Basic Captcha example project shows the most basic source code required to protect an ASP.NET MVC form with BotDetect CAPTCHA and validate the user input.

ASP.NET MVC View code displaying CAPTCHA protection can be found in Views/Example/Index.aspx, and the ASP.NET MVC Controller code checking user input is in Controllers/ExampleController.vb.

ASP.NET MVC Default Source Code Folder Online Source
ASP.NET MVC 5.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET4.5\WebApp\ AspNetMvc50BasicCaptchaExample
ASP.NET MVC 4.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET4.5\WebApp\ AspNetMvc40BasicCaptchaExample

ASP.NET MVC Internet Application CAPTCHA Example

This example project shows how to use the BotDetect MvcCaptcha control in ASP.NET MVC web applications.

Starting with the default ASP.NET MVC example project, the example includes all code required to add Captcha validation to the Account controller Register action.

ASP.NET MVC Default Source Code Folder Online Source
ASP.NET MVC 5.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET4.5\WebApp\ AspNetMvc50CaptchaExample
ASP.NET MVC 4.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET4.5\WebApp\ AspNetMvc40CaptchaExample
ASP.NET MVC 3.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET4.0\WebApp\ AspNetMvc30CaptchaExample
ASP.NET MVC 2.0

C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET4.0\WebApp\ AspNetMvc20CaptchaExample

and

C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET3.5\WebApp\ AspNetMvc20CaptchaExample

ASP.NET MVC 1.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET3.5\WebApp\ AspNetMvc10CaptchaExample

ASP.NET MVC jQuery Ajax CAPTCHA Example

The ASP.NET MVC jQuery Ajax Captcha VB.NET ASPX example project shows how to perform Ajax Captcha validation using a jQuery $.getJSON call on the client combined with an ASP.NET MVC JsonResult Controller action on the server.

Both the client-side code (located in Scripts\CheckCaptcha.js) and the server-side code (Controllers\ExampleController.vb) are very simple, and allow BotDetect Captcha protection to be added in a variety of custom Ajax forms and scenarios.

ASP.NET MVC Default Source Code Folder Online Source
ASP.NET MVC 5.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET4.5\WebApp\ AspNetMvc50AjaxCaptchaExample
ASP.NET MVC 4.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET4.5\WebApp\ AspNetMvc40AjaxCaptchaExample

BotDetect.Web.Mvc ASP.NET CAPTCHA Reference

The BotDetect.Web.Mvc namespace encapsulates BotDetect types specific to ASP.NET MVC Captcha implementations. It's separated from the main BotDetect assembly into BotDetect.Web.Mvc.dll so referencing BotDetect doesn't cause a dependency on ASP.NET MVC (unless BotDetect.Web.Mvc.dll is also referenced).

BotDetect.Web.UI.Mvc.MvcCaptcha Class Reference

A BotDetect Captcha control variant used for ASP.NET MVC applications.

Read the full BotDetect.Web.Mvc.MvcCaptcha class API reference...

BotDetect.Web.Mvc.CaptchaValidationAttribute Class Reference

An ActionFilterAttribute sub-class setting RouteData depending on the Captcha validation result.

Read the full BotDetect.Web.Mvc.CaptchaValidationAttribute class API reference...

System.Web.Mvc.CaptchaHtmlHelper Class Reference

A HtmlHelper extension used for generating Captcha markup.

Read the full System.Web.Mvc.CaptchaHtmlHelper class API reference...

ASP.NET MVC CAPTCHA FAQ

ASP.NET MVC Version Compatibility

I'm trying to add BotDetect to my ASP.NET MVC application, but I'm getting "Could not load file or assembly 'System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference." errors when I try to run it. Your component seems to be referencing an older version of ASP.NET MVC, which is not installed on my system.

Read the answer...

ASP.NET MVC No Captcha Code Model Field

Your ASP.NET MVC integration instructions start by adding a CaptchaCode field to a Model class, which conflicts with our requirements. Can we add BotDetect Captcha protection to a Controller action without adding any fields to the Model declarations?

Read the answer...

ASP.NET MVC Resource-Based Error Message Localization

How do I use localized Captcha validation error messages from ASP.NET MVC application resources? If I use [CaptchaValidation("Captcha", "RegistrationCaptcha", Resources.Error.CaptchaMismatch)], I get "An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type" errors.

Read the answer...