The BotDetect CAPTCHA NuGet Package

Unlike Recaptcha the Stalker -- BotDetect CAPTCHA works in China! Licensable source-code; self-hosted -- doesn't stalk -- nor does it slurp your form-data! Think: GDPR & LGPD!

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 MvcSimpleCaptcha object and pass it to the SimpleCaptcha HtmlHelper:

@using BotDetect.Web.Mvc;

@{ MvcSimpleCaptcha exampleCaptcha = new MvcSimpleCaptcha("ExampleCaptcha"); }
@Html.SimpleCaptcha(exampleCaptcha)
@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" });

Check User Input During Form Submission

Mark the protected Controller action with the SimpleCaptchaValidation attribute to include Captcha validation in ModelState.IsValid checks:
using BotDetect.Web.Mvc;
  
  […]

[HttpPost]
[AllowAnonymous]
[SimpleCaptchaValidation("CaptchaCode", "ExampleCaptcha", "Incorrect CAPTCHA code!")]
public ActionResult ExampleAction(ExampleModel model)
{
    if (!ModelState.IsValid)
    {  
      // TODO: SimpleCaptcha validation failed, show error message      
    }  
    else
    {  
      // TODO: SimpleCaptcha validation passed, proceed with protected action  

    }  

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

NuGet CAPTCHA Integration into ASP.NET Web Pages Applications

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

@{
    SimpleCaptcha exampleCaptcha = new SimpleCaptcha("ExampleCaptcha");
}

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

@if ((Request.HttpMethod == "POST"))
{
    bool isHuman = exampleCaptcha.Validate();
    if (isHuman)
    {
    <span class="correct">Correct!</span>
    }
    else
    {
    <span class="incorrect">Incorrect!</span>
    }
}

Detailed ASP.NET Web Pages integration instructions can be found in the ASP.NET Web Pages SimpleCaptcha integration guide.

NuGet CAPTCHA Integration into ASP.NET WebForms Applications

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

<BotDetect:SimpleCaptcha ID="ExampleCaptcha" runat="server" />
<asp:TextBox ID="CaptchaCodeTextBox" runat="server" />

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

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

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

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