BotDetect CAPTCHA ASP.NET Code Samples

First Time Here?

Check the BotDetect Developer Crash Course for key integration steps.

The BotDetect ASP.NET Captcha installations include 10 sample projects which can help you get started with integrating BotDetect in your applications and configuring various Captcha options.

Samples are divided by the .NET runtime version used, and each sample comes in both C# and VB.NET versions.

Table of Contents

BotDetect CAPTCHA ASP.NET Code Samples Installation

When you install the BotDetect ASP.NET Captcha control, you'll be given a choice of features to install:

BotDetect ASP.NET Setup feature selection

Note that:

  • By default, all features are selected
  • You can choose which .NET runtime versions you want to support. Each of the options has separate BotDetect assemblies, configuration files and web applications.
  • Selecting Samples and Demos under each .NET version installs the BotDetect web application files – demos and samples source code.
  • Selecting Deploy to IIS under each .NET versions deploys the BotDetect web applications to localhost, creating IIS applications and application pools running the selected .NET runtime version.
  • If setup detects that you don't have IIS and the required .NET Framework version installed on the machine, the Deploy to IIS option won't be shown.

When the web applications are installed, you can view their source code in the BotDetect installation folder and run them using the provided Start Menu shortcuts:

.NET Version Default Installation Folder Start Menu Shortcut
.NET 4.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\ Asp.Net\v4.5\WebApp Start -> Programs -> Lanapsoft -> BotDetect 3 CAPTCHA Component -> ASP.NET -> DotNET 4.5 Web Applications
.NET 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\ Asp.Net\v4.0\WebApp Start -> Programs -> Lanapsoft -> BotDetect 3 CAPTCHA Component -> ASP.NET -> DotNET 4.0 Web Applications
.NET 3.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\ Asp.Net\v3.5\WebApp Start -> Programs -> Lanapsoft -> BotDetect 3 CAPTCHA Component -> ASP.NET -> DotNET 3.5 Web Applications
.NET 2.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\ Asp.Net\v2.0\WebApp Start -> Programs -> Lanapsoft -> BotDetect 3 CAPTCHA Component -> ASP.NET -> DotNET 2.0 Web Applications

BotDetect CAPTCHA ASP.NET Developer Crash Course

Be sure to check our Developer Crash Course to quickly learn the few key integration steps.

BotDetect ASP.NET WebForms CAPTCHA Integration Samples

These code samples show how to integrate BotDetect in your ASP.NET WebForms applications.

ASP.NET Basic Captcha Sample

This sample project shows the most basic source code required to protect an ASP.NET form with BotDetect Captcha and validate the user input.

It can be used as a starting point when you are first learning how to use BotDetect.

.NET Version Default Source Code Folder Online Source
.NET 4.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\AspNetBasicCaptchaSample
.NET 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.0\WebApp\AspNetBasicCaptchaSample
.NET 3.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v3.5\WebApp\AspNetBasicCaptchaSample
.NET 2.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v2.0\WebApp\AspNetBasicCaptchaSample

ASP.NET Custom Captcha Validator Sample

This sample project shows how to use the CaptchaValidator control to integrate BotDetect Captcha validation with standard ASP.NET page validation functionality and other validator controls.

.NET Version Default Source Code Folder Online Source
.NET 4.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\AspNetValidatorCaptchaSample
.NET 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.0\WebApp\AspNetValidatorCaptchaSample
.NET 3.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v3.5\WebApp\AspNetValidatorCaptchaSample
.NET 2.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v2.0\WebApp\AspNetValidatorCaptchaSample

ASP.NET Membership Captcha Sample

This sample project shows how to integrate BotDetect Captcha validation with standard ASP.NET Membership functionality used in ASP.NET Login and CreateUserWizard controls.

.NET Version Default Source Code Folder Online Source
.NET 4.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\ AspNetMembershipCaptchaSample
.NET 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.0\WebApp\ AspNetMembershipCaptchaSample
.NET 3.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v3.5\WebApp\ AspNetMembershipCaptchaSample
.NET 2.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v2.0\WebApp\ AspNetMembershipCaptchaSample

ASP.NET 4.5 WebForms Application CAPTCHA Sample

This sample project shows how to add BotDetect CAPTCHA protection to the registration form included in the default ASP.NET 4.5 Web Forms Application project template coming with Visual Studio 2012.

Since the Register form uses a CreateUserWizard, the sample shows how to include BotDetect CAPTCHA validation in new user data validation (see Account\Register.aspx and Account\Register.aspx.cs source code).

The sample also shows how to complement server-side CAPTCHA validation with client-side Ajax CAPTCHA validation using ASP.NET 4.5 unobtrusive validation applied to all form fields (Scripts\WebForms\WebUICaptchaValidation.js).

ASP.NET Default Source Code Folder Online Source
ASP.NET 4.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\ AspNetWebForms45CaptchaSample

ASP.NET Ajax Captcha Sample

This sample project shows how to use BotDetect within an ASP.NET Ajax UpdatePanel. The basic code used to add Captcha protection to the page is the same as in regular ASP.NET forms.

However, some additional work is required if BotDetect is not visible on the first page load, but gets added to the page dynamically.

ASP.NET Ajax Version Default Source Code Folder Online Source
ASP.NET Ajax 4.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\ AspNetAjax40CaptchaSample
ASP.NET Ajax 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.0\WebApp\ AspNetAjax40CaptchaSample
ASP.NET Ajax 1.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v3.5\WebApp\ AspNetAjax10CaptchaSample

ASP.NET jQuery Validation Captcha Sample

This sample project shows how to integrate BotDetect ASP.NET Captcha validation with jQuery Validation client-side form validation.

Client-side validation is not secure by itself (it can be bypassed trivially by bots that don't execute JavaScript at all), so the sample shows how the protected form action must always be secured by server-side Captcha validation first, and uses client-side validation only to improve the user experience.

.NET Version Default Source Code Folder Online Source
.NET 4.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\ AspNetJQueryValidationCaptchaSample
.NET 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.0\WebApp\ AspNetJQueryValidationCaptchaSample
.NET 3.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v3.5\WebApp\ AspNetJQueryValidationCaptchaSample
.NET 2.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v2.0\WebApp\ AspNetJQueryValidationCaptchaSample

ASP.NET Built-In Ajax Captcha Validation Sample

This sample project shows how to properly perform Ajax Captcha validation using built-in BotDetect client-side functionality, which doesn't require any 3rd party Ajax frameworks.

Ajax Captcha validation improves the user experience by reducing Captcha validation response time, giving users much faster feedback about the validation result.

.NET Version Default Source Code Folder Online Source
.NET 4.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\CaptchaAjaxValidationSample
.NET 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.0\WebApp\CaptchaAjaxValidationSample
.NET 3.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v3.5\WebApp\CaptchaAjaxValidationSample
.NET 2.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v2.0\WebApp\CaptchaAjaxValidationSample

BotDetect ASP.NET MVC CAPTCHA Integration Samples

These code samples show how to integrate BotDetect in your ASP.NET MVC applications.

ASP.NET MVC Basic CAPTCHA Sample

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

ASP.NET MVC View code displaying CAPTCHA protection can be found in Views/Sample/Index.aspx, and the ASP.NET MVC Controller code checking user input is in Controllers/SampleController.vb.

ASP.NET MVC Default Source Code Folder Online Source
ASP.NET MVC 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\ AspNetMvc40BasicCaptchaSample

ASP.NET MVC Internet Application CAPTCHA Sample

This sample project shows how to use the BotDetect MvcCaptcha control in ASP.NET MVC web applications.

Starting with the default ASP.NET MVC sample project, the sample includes all code required to add Captcha validation to the Account controller Register action.

ASP.NET MVC Default Source Code Folder Online Source
ASP.NET MVC 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\ AspNetMvc40CaptchaSample
ASP.NET MVC 3.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.0\WebApp\ AspNetMvc30CaptchaSample
ASP.NET MVC 2.0

C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.0\WebApp\ AspNetMvc20CaptchaSample

and

C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v3.5\WebApp\ AspNetMvc20CaptchaSample

ASP.NET MVC 1.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v3.5\WebApp\ AspNetMvc10CaptchaSample

ASP.NET MVC jQuery Ajax CAPTCHA Sample

The ASP.NET MVC 4.0 jQuery Ajax Captcha VB.NET ASPX sample project shows how to perform Ajax Captcha validation using a jQuery $.getJSON call on the client combined with an ASP.NET MVC 4.0 JsonResult Controller action on the server.

Both the client-side code (located in Scripts\CheckCaptcha.js) and the server-side code (Controllers\SampleController.vb) are very simple, and allow BotDetect Captcha protection to be added in a variety of custom Ajax forms and scenarios.

ASP.NET MVC Default Source Code Folder Online Source
ASP.NET MVC 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\ AspNetMvc40AjaxCaptchaSample

BotDetect ASP.NET CAPTCHA Configuration Samples

Captcha configuration code samples show how to use particular BotDetect Captcha options in your ASP.NET applications

ASP.NET CAPTCHA Code Filtering Sample

This sample project shows how to use the new Captcha code filtering functionality added in BotDetect 3.0.

You can define rules about character sequences you want to avoid using in randomly generated Captcha codes and simply pass them to the Captcha control.

.NET Version Default Source Code Folder Online Source
.NET 4.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\CaptchaCodeFilteringSample
.NET 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.0\WebApp\CaptchaCodeFilteringSample
.NET 3.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v3.5\WebApp\CaptchaCodeFilteringSample
.NET 2.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v2.0\WebApp\CaptchaCodeFilteringSample

ASP.NET CAPTCHA Customization Sample

This sample project shows how to customize BotDetect Captcha behavior and appearance.

BotDetect 3.0 allows user-defined customization of many Captcha options through a custom <botDetect> configuration section in the web.config file; some customizations also require code-behind changes.

The web.config file used in this sample project contains detailed descriptions and explanations of the many customizable options.

You can then use chosen customization options to configure BotDetect to precisely match your application requirements.

.NET Version Default Source Code Folder Online Source
.NET 4.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\CaptchaCustomizationSample
.NET 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.0\WebApp\CaptchaCustomizationSample
.NET 3.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v3.5\WebApp\CaptchaCustomizationSample
.NET 2.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v2.0\WebApp\CaptchaCustomizationSample

ASP.NET CAPTCHA Randomization Sample

This sample project shows how to easily randomize various Captcha control parameters, beyond the basic image and sound style randomization used by default.

Randomly using different Captcha image and sound generation algorithms and other parameter values (such as code length and style) can significantly improve the Captcha security.

This is the recommended approach to Captcha property setting, since it takes full advantage of the 60 Captcha image and 10 Captcha sound generation algorithms shipped with BotDetect, as well as built-in randomization features.

.NET Version Default Source Code Folder Online Source
.NET 4.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\CaptchaRandomizationSample
.NET 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.0\WebApp\CaptchaRandomizationSample
.NET 3.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v3.5\WebApp\CaptchaRandomizationSample
.NET 2.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v2.0\WebApp\CaptchaRandomizationSample

BotDetect ASP.NET CAPTCHA Troubleshooting Samples

Captcha options code sample projects show how to use particular BotDetect Captcha options in your ASP.NET applications

ASP.NET CATCHA Built-In Troubleshooting Sample

This sample project shows how to use BotDetect built-in error logging and Captcha event tracing, using the BotDetect Troubleshooting utility based on log4net.

Such logging techniques can be used as a foundation for effective diagnosis and resolution of any BotDetect issues you might encounter on your servers.

.NET Version Default Source Code Folder Online Source
.NET 4.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.5\WebApp\CaptchaTroubleshootingSample
.NET 4.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v4.0\WebApp\CaptchaTroubleshootingSample
.NET 3.5 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v3.5\WebApp\CaptchaTroubleshootingSample
.NET 2.0 C:\Program Files\Lanapsoft\BotDetect 3 CAPTCHA Component\Asp.Net\v2.0\WebApp\CaptchaTroubleshootingSample