The BotDetect CAPTCHA NuGet Package (BotDetect v3.0; deprecated)

The free version of BotDetect ASP.NET Captcha is also available as a NuGet package in the www.nuget.org NuGet Gallery: CAPTCHA NuGet package.

To install CAPTCHA using NuGet, right-click your project in Visual Studio, select "Manage NuGet Packages…" and search for "BotDetect", or run the following command in the Package Manager Console:

PM> Install-Package Captcha

After adding the Captcha NuGet package to your application, check the following resources:

NuGet CAPTCHA Integration Instructions

To show a Captcha challenge on the form and check user input during form submission:

NuGet CAPTCHA Integration into ASP.NET MVC Applications

In View code: import the BotDetect namespace, include BotDetect styles in page , create a MvcCaptcha object and pass it to the Captcha HtmlHelper:

@using BotDetect.Web.UI.Mvc;

  […]

  <link href="@BotDetect.Web.CaptchaUrls.Absolute.LayoutStyleSheetUrl"
    rel="stylesheet" type="text/css" />
</head>

  […]

@{ MvcCaptcha sampleCaptcha = new MvcCaptcha("SampleCaptcha"); }
@Html.Captcha(sampleCaptcha)
@Html.TextBox("CaptchaCode")

Exclude BotDetect paths from ASP.NET MVC Routing:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    // BotDetect requests must not be routed
    routes.IgnoreRoute("{*botdetect}", 
      new { botdetect = @"(.*)BotDetectCaptcha\.ashx" });

Mark the protected Controller action with the CaptchaValidation attribute to include Captcha validation in ModelState.IsValid checks:

using BotDetect.Web.UI.Mvc;
  
  […]

[HttpPost]
[AllowAnonymous]
[CaptchaValidation("CaptchaCode", "SampleCaptcha", "Incorrect CAPTCHA code!")]
public ActionResult SampleAction(SampleModel model)
{
    if (!ModelState.IsValid)
    {  
      // TODO: Captcha validation failed, show error message      
    }  
    else
    {  
      // TODO: Captcha validation passed, proceed with protected action  
    }  

Detailed ASP.NET MVC integration instructions can be found in the ASP.NET MVC Captcha integration guide.

NuGet CAPTCHA Integration into ASP.NET WebForms Applications

On the ASP.NET form you want to protect against bots, add:

<BotDetect:Captcha ID="SampleCaptcha" runat="server" />
<asp:TextBox ID="CaptchaCodeTextBox" runat="server" />

When the form is submitted, the Captcha validation result must be checked:

if (IsPostBack)
{
    // validate the Captcha to check we're not dealing with a bot
    bool isHuman = SampleCaptcha.Validate(CaptchaCodeTextBox.Text);
    
    CaptchaCodeTextBox.Text = null; // clear previous user input

    if (!isHuman)
    {
      // TODO: Captcha validation failed, show error message  
    }
    else
    {
      // TODO: Captcha validation passed, proceed with protected action  
    }
}

Detailed ASP.NET WebForms integration instructions can be found in the ASP.NET WebForms Captcha integration guide.

BotDetect CAPTCHA Code Samples Download

Captcha code samples (ASP.NET WebForms integration samples, ASP.NET MVC integration samples, BotDetect configuration samples - with both C# and VB.NET and ASPX/Razor variants), as well as equivalents for older .NET framework versions and additional resources are included in the BotDetect setup package which can be downloaded from the BotDetect Captcha download page.

BotDetect CAPTCHA Documentation

The full index of available BotDetect ASP.NET CAPTCHA documentation can be found on the BotDetect documentation page.


Please Note

The information on this page is out of date and applies to a deprecated version of BotDetect™ CAPTCHA (v3.0).

An up-to-date equivalent page for the latest BotDetect Captcha release (v4) is BotDetect v4 Captcha documentation index.

General information about the major improvements in the current BotDetect release can be found at the What's New in BotDetect v4.0 page.