BotDetect CAPTCHA ASP.NET Code Examples



First Time Here?

Check the BotDetect Developer Crash Course for key integration steps.

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

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

Table of Contents

BotDetect CAPTCHA ASP.NET Code Examples Installation

When you install the BotDetect ASP.NET Captcha Simple API 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 Examples under each .NET version installs the BotDetect web application files – ASP.NET code examples 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 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\ Asp.Net\.NET\WebApp Start -> Programs -> Captcha Inc -> BotDetect 4 CAPTCHA Component -> ASP.NET -> ASP.NET Examples
.NET4.5.1+ASP.NET-CORE C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\ Asp.Net\.NET4.5.1+ASP.NET-CORE\WebApp Start -> Programs -> Captcha Inc -> BotDetect 4 CAPTCHA Component -> ASP.NET -> ASP.NET Core on .NET 4.5.1+ Examples
.NET Core C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\ Asp.Net\.NET-CORE\WebApp Start -> Programs -> Captcha Inc -> BotDetect 4 CAPTCHA Component -> ASP.NET -> ASP.NET Core on .NET Core 1.x 2.x Examples

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 Examples

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

ASP.NET Basic SimpleCaptcha Example

This example project shows the most basic source code required to protect an ASP.NET form with BotDetect SimpleCaptcha 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 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ WebFormsBasicCaptchaExample

ASP.NET Custom SimpleCaptcha Validator Example

This example project shows how to use the SimpleCaptchaValidator control to integrate BotDetect SimpleCaptcha validation with standard ASP.NET page validation functionality and other validator controls.

.NET Version Default Source Code Folder Online Source
.NET C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ WebFormsValidatorCaptchaExample

ASP.NET Membership SimpleCaptcha Example

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

.NET Version Default Source Code Folder Online Source
.NET C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ WebFormsMembershipCaptchaExample

ASP.NET Template SimpleCaptcha Example

This example project shows how to add BotDetect CAPTCHA protection to the registration form included in the default project template coming with Visual Studio 2015 / Visual Studio 2013 / Visual Studio 2012.

Since the Register form uses a CreateUserWizard, the example shows how to include BotDetect CAPTCHA validation in new user data validation.

The example also shows how to complement server-side CAPTCHA validation with client-side Ajax CAPTCHA validation using ASP.NET unobtrusive validation applied to all form fields.

Visual Studio Default Source Code Folder Online Source
Visual Studio 2015 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ WebFormsVS2015AppTemplateExample
Visual Studio 2013 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ WebFormsVS2013AppTemplateExample
Visual Studio 2012 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ WebFormsVS2012AppTemplateExample

BotDetect ASP.NET MVC CAPTCHA Integration Examples

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

ASP.NET MVC Basic CAPTCHA Example

The ASP.NET MVC Basic Captcha Simple API example 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/Example/Index.aspx, and the ASP.NET MVC Controller code checking user input is in Controllers/ExampleController.vb.

ASP.NET MVC Default Source Code Folder Online Source
ASP.NET MVC 5.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ Mvc50BasicCaptchaExample
ASP.NET MVC 4.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ Mvc40BasicCaptchaExample

ASP.NET MVC Application Template CAPTCHA Example

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

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

ASP.NET MVC Default Source Code Folder Online Source
ASP.NET MVC 5.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ Mvc50ApplicationTemplateCaptchaExample
ASP.NET MVC 4.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ Mvc40CaptchaExample
ASP.NET MVC 3.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ Mvc30CaptchaExample
ASP.NET MVC 2.0

C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ Mvc20CaptchaExample

ASP.NET MVC 1.0 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ Mvc10CaptchaExample

ASP.NET MVC Single Page Application CAPTCHA Example

The ASP.NET MVC Single Page Application Captcha Simple API example 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/Account/Register.aspx, and the ASP.NET MVC Controller code checking user input is in Controllers/AccountController.vb.

ASP.NET MVC Default Source Code Folder Online Source
ASP.NET MVC 5.2.3 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ MvcSinglePageApplicationExample

BotDetect ASP.NET CAPTCHA Configuration Examples

SimpleCaptcha configuration code examples show how to use particular BotDetect SimpleCaptcha options in your ASP.NET applications

ASP.NET SimpleCaptcha Application Config Settings Example

This example shows how to configure SimpleCaptcha challenges by overriding SimpleCaptcha control defaults in application configuration files.

BotDetect allows user-defined customization of many SimpleCaptcha options through a special <botDetect> section of the web.config file.

SimpleCaptcha settings from this configuration file will apply to all SimpleCaptcha challenges shown on forms in the applications, and will act as defaults with which all SimpleCaptcha objects will be created. This makes configuration file settings the simplest and most convenient way of SimpleCaptcha customization for most use cases.

.NET Version Default Source Code Folder Online Source
.NET C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ CaptchaApplicationConfigSettingsExample

ASP.NET SimpleCaptcha ClientSide Workflow Settings Example

This BotDetect SimpleCaptcha ASP.NET code example shows how to use custom BotDetect client-side events to execute user-defined JavaScript code at various stages of the SimpleCaptcha challenge workflow.

Client-side SimpleCaptcha object initialization, Captcha image reloading, SimpleCaptcha sound playback, built-in SimpleCaptcha Ajax validation, and SimpleCaptcha help link clicks all have a number of related client-side "events" and hooks where user-defined client-side callbacks can be injected.

.NET Version Default Source Code Folder Online Source
.NET C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ CaptchaClientSideWorkflowSettingsExample

ASP.NET SimpleCaptcha Form Object Settings Example

This BotDetect SimpleCaptcha ASP.NET code example shows how to configure SimpleCaptcha challenges by setting SimpleCaptcha control properties in ASP.NET form source.

Multiple ASP.NET forms within the same ASP.NET website can be protected by BotDetect SimpleCaptcha challenges: e.g. you could add SimpleCaptcha controls in both your Contact form and Registration form source.

.NET Version Default Source Code Folder Online Source
.NET C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ CaptchaFormObjectSettingsExample

ASP.NET SimpleCaptcha Request Dynamic Settings Example

This BotDetect SimpleCaptcha ASP.NET code example shows how to dynamically adjust SimpleCaptcha configuration, potentially on each Http request made by the client.

Any code setting SimpleCaptcha properties in the SimpleCaptcha.InitializedWebCaptcha event handler will be executed not only for each protected form GET or POST request (like SimpleCaptcha configuration code placed in form source would be), but also for each each GET request loading a Captcha image or sound, or making an Ajax SimpleCaptcha validation call.

.NET Version Default Source Code Folder Online Source
.NET C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ CaptchaRequestDynamicSettingsExample

BotDetect ASP.NET CAPTCHA Web Pages Examples

ASP.NET CATCHA Web Pages Example

This 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.

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

.NET Version Default Source Code Folder Online Source
.NET 4.5 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\NET\WebApp\SimpleAPI\ WebPagesBasicCaptchaExample

ASP.NET Website Razor 3 SimpleCaptcha Example

This example project shows the most basic source code required to protect an ASP.NET Web Pages form using new Razor syntax with BotDetect CAPTCHA and validate the user input.

ASP.NET Web Pages code displaying CAPTCHA protection and checking user input can be found in Account\Register.cshtml.

.NET Version Default Source Code Folder Online Source
.NET 4.6 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ WebSiteRazor3CaptchaExample

BotDetect ASP.NET CAPTCHA Troubleshooting Examples

SimpleCaptcha options code example projects show how to use particular BotDetect SimpleCaptcha options in your ASP.NET applications

ASP.NET CATCHA Built-In Troubleshooting Example

This example project shows how to use BotDetect built-in error logging and SimpleCaptcha 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 C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\ CaptchaTroubleshootingExample