ASP.NET Web Pages Basic CAPTCHA VB.NET Code Example

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

First Time Here?

Check the BotDetect Developer Crash Course for key integration steps.

ASP.NET Web Pages code displaying CAPTCHA protection and checking user input can be found in Index.vbhtml.

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

Visual Studio 2017, 2015, 2013 / .NET 4.5 and onwards

By default, the VB.NET version of the ASP.NET Web Pages basic Captcha example project is installed at:
C:\Program Files\Captcha Inc\BotDetect CAPTCHA\aspnetlegacy+netlegacy\Examples\TraditionalAPI\WebPagesBasicCaptchaExample\VBNet

You can also run it from the BotDetect Start Menu:
Programs > Captcha Inc > BotDetect CAPTCHA > ASPNETLEGACY + NETLEGACY Examples > Legacy ASP.NET + Legacy .NET Run code examples


@* namespace needed to access BotDetect members *@ 
@Imports BotDetect.Web 

<!DOCTYPE html> 
<html lang="en"> 

  <meta charset="utf-8" /> 
  <title>BotDetect ASP.NET CAPTCHA Validation: Basic ASP.NET Web Pages CAPTCHA 
  Code Example</title> 
  <link href="@CaptchaUrls.Absolute.LayoutStyleSheetUrl" rel="stylesheet" 
  type="text/css" /> 
  <link href="StyleSheet.css" rel="stylesheet" type="text/css" /> 

  <form method="post" class="column"> 
    <h1>BotDetect ASP.NET CAPTCHA Validation: <br /> Basic ASP.NET Web Pages 
    CAPTCHA Code Example</h1> 
      <legend>ASP.NET Web Pages CAPTCHA Validation</legend> 
      @Html.Label("Retype the code from the picture:", "CaptchaCode") 
        Dim exampleCaptcha As Captcha = New Captcha("ExampleCaptcha") 
        exampleCaptcha.UserInputID = "CaptchaCode" 
      End Code 
      <div class="validationDiv"> 
        <input type="submit" value="Validate" /> 
        @If ((Request.HttpMethod = "POST")) Then 
          Dim isHuman As Boolean = exampleCaptcha.Validate() 
          If (isHuman) Then 
          @<span class="correct">Correct!</span> 
          @<span class="incorrect">Incorrect!</span> 
          End If 
        End If 


<?xml version="1.0"?> 
    <section name="botDetect" requirePermission="false" 
    type="BotDetect.Configuration.BotDetectConfigurationSection, BotDetect"/> 
    <add key="webPages:Version" value="2.0"/> 
  <compilation debug="false" targetFramework="4.0"/> 
    <!-- Register the HttpHandler used for BotDetect Captcha requests --> 
    <add verb="GET" path="BotDetectCaptcha.ashx" 
    type="BotDetect.Web.CaptchaHandler, BotDetect"/> 
  <!-- Register a custom SessionIDManager for BotDetect Captcha requests --> 
  <sessionState mode="InProc" cookieless="false" timeout="20" 
  sessionIDManagerType="BotDetect.Web.CustomSessionIdManager, BotDetect"/> 
  <validation validateIntegratedModeConfiguration="false"/> 
    <!-- Register the HttpHandler used for BotDetect Captcha requests (IIS 7.0+) --> 
    <remove name="BotDetectCaptchaHandler"/> 
    <add name="BotDetectCaptchaHandler" preCondition="integratedMode" verb="GET" 
    path="BotDetectCaptcha.ashx" type="BotDetect.Web.CaptchaHandler, BotDetect"/> 
  <botDetect helpLinkEnabled="true" helpLinkMode="image" />