How do I add a CAPTCHA to a web site written with ASP.NET/VB

Robert Barnes 71 Reputation points

A bot seems to be using my web site to send out emails via AmazonSES. I want to add a CAPTCHA to it to prevent this. I came across

which appears to be what I want, but the examples use C# rather than VB. I tried to convert the C# to VB, but I got into a mess.

I checked the similar questions through this forum and found this

which tells me that reCAPTCHA is not supported on this forum. So is there something that works with ASP/NET (VB)?

Any useful information will be appreciated.

Thank you, Robert.

A set of technologies in the .NET Framework for building web applications and XML web services.
3,323 questions
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,610 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 26,686 Reputation points Microsoft Vendor

    Hi @Robert Barnes,

    You can use the MSCaptcha Library in ASP.Net.

    Download MSCaptcha

    In order to use MSCaptcha control, you will need to add reference of MSCaptcha Library and then register on the Page as shown below.

    <%@ Register Assembly="MSCaptcha" Namespace="MSCaptcha" TagPrefix="cc1" %>

    Web.Config Modifications:

    		<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
        <compilation debug="true" strict="false" explicit="true" targetFramework="4.8" />
    		  <add verb="GET" path="CaptchaImage.axd" type="MSCaptcha.CaptchaImageHandler, MSCaptcha"/>
        <httpRuntime targetFramework="4.8" />
          <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    		<validation validateIntegratedModeConfiguration="false"/>
    			<add name="MSCaptcha.captchaImageHandler" verb="GET" path="CaptchaImage.axd" type="MSCaptcha.CaptchaImageHandler, MSCaptcha" resourceType="Unspecified"/>


    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    <%@ Register Assembly="MSCaptcha" Namespace="MSCaptcha" TagPrefix="cc1" %>
    <!DOCTYPE html>
    <html xmlns="">
    <head runat="server">
        <form id="form1" runat="server">
                <cc1:CaptchaControl ID="captcha1" runat="server" CaptchaBackgroundNoise="Low" CaptchaLength="5"
                    CaptchaHeight="60" CaptchaWidth="200" CaptchaLineNoise="None" CaptchaMinTimeout="5"
                    CaptchaMaxTimeout="240" FontColor="#529E00" ErrorInputTooFast="Image text was typed too quickly. " ErrorInputTooSlow="Image text was typed too slowly." EnableViewState="False" />
                <asp:TextBox ID="txtCaptcha" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvCaptcha" runat="server" ErrorMessage="*Required"
                    ControlToValidate="txtCaptcha" Display="Dynamic"></asp:RequiredFieldValidator>
                <asp:Label ID="lblMessage" runat="server"></asp:Label>
                <br />
                <br />
                <asp:Button ID="btnVerify" runat="server" Text="Verify" OnClick="OnVerify" />
    Imports System.Drawing
    Partial Class _Default
        Inherits System.Web.UI.Page
        Protected Sub OnVerify(sender As Object, e As System.EventArgs)
            If captcha1.UserValidated Then
                lblMessage.ForeColor = Color.Green
                lblMessage.Text = "Valid"
                lblMessage.ForeColor = Color.Red
                lblMessage.Text = "InValid"
            End If
        End Sub
    End Class

    User's image

    Best regards,
    Lan Huang

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.