BotDetect ASP.NET WebPages CAPTCHA Integration Quickstart

1. Add a Reference to BotDetect and SQLite

The BotDetect.dll assembly should be referenced. They are included in the BotDetect installation.

By default, BotDetect ASP.NET CAPTCHA Simple API uses SQLite as the default persistence provider for storing captcha data, so you need to ensure SQLite assembly is referenced in your project. Here is where you can find the SQLite installation guide. Or check any Simple API examples that are installed with BotDetect.

2. Show a Captcha Challenge on the Form

Import the BotDetect namespace, include BotDetect styles in page <head>, create a SimpleCaptcha object and pass it to the SimpleCaptcha HtmlHelper:
@using BotDetect.Web; 
  
  
  @{
    SimpleCaptcha exampleCaptcha = new SimpleCaptcha("ExampleCaptcha");
  }
  @Html.Raw(exampleCaptcha.Html)
  @Html.TextBox("CaptchaCode")
  

3. Check User Input During Form Submission

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>
    }
  }

4. Configure Your ASP.NET Application

Update your application configuration (the web.config file):
<system.web>
  <httpHandlers>
    <!-- Register the HttpHandler used for BotDetect Simple API 
      requests -->
    <add verb="GET" path="BotDetectCaptcha.ashx"
      type="BotDetect.Web.SimpleCaptchaHandler, BotDetect"/>
  </httpHandlers>
  


</system.web>
<system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>
  <handlers>
    <!-- Register the HttpHandler used for BotDetect Simple API 
      requests (IIS 7.0+) -->
    <remove name="BotDetectCaptchaHandler"/>
    <add name="BotDetectCaptchaHandler" preCondition="integratedMode" 
      verb="GET" path="BotDetectCaptcha.ashx"
      type="BotDetect.Web.SimpleCaptchaHandler, BotDetect"/>
  </handlers>
</system.webServer>

5. Configure Captcha options

Configure captcha options in botdetect.xml configuration file. By default, this file is located at the root of your project.

<?xml version="1.0" encoding="UTF-8"?>
<botdetect xmlns="https://captcha.com/schema/net"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="https://captcha.com/schema/net 
     https://captcha.com/schema/net/botdetect-4.4.0.xsd">

  <captchaStyles>
    <captchaStyle>
      <name>ExampleCaptcha</name>
      <userInputID>CaptchaCode</userInputID>
      <codeLength>3-5</codeLength>
    </captchaStyle>
  </captchaStyles>

</botdetect>

Other BotDetect ASP.NET CAPTCHA Quickstarts

ASP.NET WebForms Basic CAPTCHA.

ASP.NET MVC CAPTCHA.