Garima Bansal

Garima Bansal

  • 1.1k
  • 669
  • 38.6k

captcha in asp.net

Mar 3 2023 5:20 AM

implement captcha in form, i am trying to implement captcha in this way

<%@ Register Assembly="MSCaptcha" Namespace="MSCaptcha" TagPrefix="cc1" %>
<div>  
<cc1:CaptchaControl ID="cptCaptcha" runat="server"  
    CaptchaBackgroundNoise="Low" CaptchaLength="5"  
    CaptchaHeight="60" CaptchaWidth="200"  
    CaptchaLineNoise="None" CaptchaMinTimeout="5"  
    CaptchaMaxTimeout="240" FontColor = "#529E00" />  
</div>  
    <asp:TextBox ID="txtCaptcha" runat="server"></asp:TextBox>  
    <br />  
    <asp:Button ID="btnVerify" runat="server" Text="Verify Image" OnClick="btnVerify_Click" />  
    <asp:RequiredFieldValidator ID="RequiredFieldValidator15" runat="server" ErrorMessage="*Required" ControlToValidate = "txtCaptcha"></asp:RequiredFieldValidator> 
        <asp:Label ID="lblErrorMessage" runat="server" Font-Names = "Arial" Text=""></asp:Label> 
protected void btnVerify_Click(object sender, EventArgs e)
{
    cptCaptcha.ValidateCaptcha(txtCaptcha.Text.Trim());
    if (cptCaptcha.UserValidated)
    {
        lblErrorMessage.ForeColor = System.Drawing.Color.Green;
        lblErrorMessage.Text = "Valid text";
    }
    else
    {
        lblErrorMessage.ForeColor = System.Drawing.Color.Red;
        lblErrorMessage.Text = "InValid Text";
    }
}

but when i use handlers in webconfig

<handlers>
    <add name ="CaptchaImage" verb ="GET" path="CaptchaImage.axd"
     type="MSCaptcha.CaptchaImageHandler, MSCaptcha" />
</handlers>

got an exception my application not run


Answers (1)