In this article I will explain how to use the free simple Captcha control called as ASPNet_Captcha in ASP.Net which allows you to make the Captcha validation simpler by providing mathematical challenges to user.

Firstly you need to add the reference of the ASPNet_Captcha to your ASP.Net Website as shown in the figure below.
Free Mathematical Captcha in ASP.Net
Now you need to add the following to the <httpHandlers> section of <system.web> or <handlers>section of <system.webServer> for IIS7 in the web.config  as shown below
    <add verb="GET" path="Image.ashx" type="ASPNET_Captcha.Image, ASPNET_Captcha" />
     <add name ="Captcha" verb="*" path="Image.ashx" type="ASPNET_Captcha.Image, ASPNET_Captcha" resourceType="Unspecified"/>
Now you simply need to add the ASPNET_Captcha Control to your ASP.Net Web page by registering it in the page header section
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<%@ Register TagPrefix="uc" Namespace="ASPNET_Captcha" Assembly="ASPNET_Captcha" %>
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    <uc:ASPNET_Captcha ID="ucCaptcha" runat="server" Align = "Middle" Color = "#FF0000" />
    <asp:TextBox ID="txtCaptcha" runat="server"></asp:TextBox>
    <br />
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="Submit" />
    <br />
    <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>
That’s it you need to make it work.
Validating the Captcha
To validate the Captcha Control you need to do the following
protected void Submit(object sender, EventArgs e)
    bool isValid = ucCaptcha.Validate(txtCaptcha.Text.Trim());
    if (isValid)
        lblMessage.Text = "Valid!";
        lblMessage.ForeColor = Color.Green;
        lblMessage.Text = "Invalid!";
        lblMessage.ForeColor = Color.Red;
Protected Sub Submit(ByVal sender As Object, ByVal e As System.EventArgs)
 Dim isValid As Boolean = ucCaptcha.Validate(txtCaptcha.Text.Trim)
 If isValid Then
       lblMessage.Text = "Valid!"
       lblMessage.ForeColor = Color.Green
       lblMessage.Text = "Invalid!"
       lblMessage.ForeColor = Color.Red
 End If
End Sub

The below screenshot describes the working the ASPNet_Captcha control
Free Mathematical Captcha in ASP.Net 3.5 4.0 2.0

Captcha Properties
In the first version of this free Captcha Control there are two properties
1. Color – This property allows you to define the color of the Captcha Text. Default is black.
2. Align – This property is useful for aligning the Captcha image along with text or other controls.
The advantage of this Captcha is that it does not make use of Session or ViewState and can be easily used with jQuery which I’ll explain in my next article.
You can download the complete sample source code in VB.Net and C# using the download link provided below.