BotDetect ASP.NET Simple CAPTCHA Options: Server Side Persistence in Memcached Database VB.NET Code Example

The ASP.NET Simple Captcha options: Server side persistence in Memcached database code example shows how to use Memcached to store persist Captcha data instead of using default BotDetect SQLite Database persistence provider.

First Time Here?

Check the BotDetect Developer Crash Course for key integration steps.

As you may know Memcached is an open source, in-memory data structure store used to improve data performance. Therefore Captcha data storage via Memcached is neccessary in real world. This combination makes your application have better performance.

To use Memcached to store persist Captcha data, BotDetect ASP.NET Simple Captcha provides you a simple way by declaring Memcached configuration info in botdetect.xml file, such as: memcached host, port.

BotDetect ASP.NET Simple Captcha uses EnyimMemcached as Memcached client, so you need to ensure EnyimMemcached NuGet package was installed.

Download the BotDetect ASP.NET CAPTCHA Library and run this example
  • C#
  • VB.NET

Installed Location

By default, the ASP.NET SimpleCaptcha persistence settings example project is installed at:
C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ CaptchaServerSidePersistenceInMemcachedDatabaseExample\VBNet

You can also run it from the BotDetect Start Menu:
Programs > Captcha Inc > BotDetect 4 CAPTCHA Component > ASP.NET > ASP.NET Examples > Run .NET Examples


<%@ Page Language="VB.NET" AutoEventWireup="true" CodeFile="Default.aspx.cs" 
Inherits="_Default" %> 

<!DOCTYPE html> 

<html xmlns=""> 
<head id="Head1" runat="server"> 
  <title>BotDetect ASP.NET CAPTCHA Options: Application Config Settings Code 

  <script type="text/javascript" 

  <form runat="server" class="column" id="form1"> 
    <h1>BotDetect ASP.NET CAPTCHA Options: 
      <br /> 
      Application Config Settings Code Example</h1> 
      <legend>ASP.NET WebForm CAPTCHA Validation</legend> 
      <p class="prompt"> 
        <label for="CaptchaCodeTextBox">Retype the characters from the picture:</label</p> 
      <BotDetect:WebFormsSimpleCaptcha runat="server" ID="MemcachedCaptchaExample"/> 
      <div class="validationDiv"> 
        <asp:TextBox ID="CaptchaCodeTextBox" runat="server"></asp:TextBox> 
        <asp:Button ID="ValidateCaptchaButton" runat="server" /> 
        <asp:Label ID="CaptchaCorrectLabel" runat="server" CssClass="correct"></asp:Label> 
        <asp:Label ID="CaptchaIncorrectLabel" runat="server" 


Partial Class _Default 
  Inherits System.Web.UI.Page 

  Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As  _ 
  System.EventArgs) Handles Me.PreRender 
    ' initial page setup 
    If Not IsPostBack Then 

      ' set control text 
      ValidateCaptchaButton.Text = "Validate" 
      CaptchaCorrectLabel.Text = "Correct!" 
      CaptchaIncorrectLabel.Text = "Incorrect!" 

      ' these messages are shown only after validation 
      CaptchaCorrectLabel.Visible = False 
      CaptchaIncorrectLabel.Visible = False 
    End If 

    If (IsPostBack) Then 

      ' validate the Captcha to check we're not dealing with a bot 
      Dim isHuman As Boolean = MemcachedCaptchaExample.Validate() 

      If (isHuman) Then 

        CaptchaCorrectLabel.Visible = True 
        CaptchaIncorrectLabel.Visible = False 


        CaptchaCorrectLabel.Visible = False 
        CaptchaIncorrectLabel.Visible = True 

      End If 
    End If 
  End Sub 
End Class 


<?xml version="1.0"?> 
  For more information on how to configure your ASP.NET application, please  
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/> 
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/> 
    <!-- Register the HttpHandler used for BotDetect Simple API requests --> 
    <add verb="GET" path="CaptchaCustomPath.ashx" 
    type="BotDetect.Web.SimpleCaptchaHandler, BotDetect"/> 
  <pages controlRenderingCompatibilityVersion="4.5" enableSessionState="true"> 
    <!-- Register the BotDetect tag prefix for easier use in all pages --> 
    <add assembly="BotDetect" namespace="BotDetect.Web.UI" 
  <compilation debug="false" targetFramework="4.5"/> 
  <httpRuntime requestValidationMode="4.5" targetFramework="4.5" 
  encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=4. 
  0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/> 
  <machineKey compatibilityMode="Framework45"/> 
  <validation validateIntegratedModeConfiguration="false"/> 
    <!-- Register the HttpHandler used for BotDetect Simple API requests (IIS 7.0+) --> 
    <remove name="BotDetectCaptchaHandler"/> 
    <add name="BotDetectCaptchaHandler" preCondition="integratedMode" verb="GET" 
    type="BotDetect.Web.SimpleCaptchaHandler, BotDetect"/> 


<?xml version="1.0" encoding="UTF-8"?> 
<botdetect xmlns="" 


In botdetect.xml configuration file, we tell BotDetect to use Memcached as the BotDetect persistence provider instead of the default one (SQLite Database). You can find the detailed explanation about this at Captcha Memcached persistence provider documentation.

Current BotDetect Versions