Tuesday 11 June 2013

How to Add a Captcha Image in ASP.NET Application

How to Add a Captcha Image in ASP.NET Application

There are some steps to Add Captcha image in Asp.NET Application. You can download whole application from the below link. Please follow steps one by one which is given below.
Step1:- First create ASP.NET page (Default.aspx) in visual studio 2010. Now click the below link to download the captcha.dll file.
see captcha.dll file:-

Description: http://2.bp.blogspot.com/-XharWgFs4xI/UCLSsS2q4lI/AAAAAAAAAnI/jyrEwRRuFvE/s640/ca1.PNG
Step2:-Now Open Solution Explorer ->Add new Folder(Bin)->open the captcha.dll file->copy all the file -> Now paste it in Bin Folder
see it:-
Description: http://4.bp.blogspot.com/-A_r8lKTrALg/UCLTEJyXO_I/AAAAAAAAAnQ/AshiDhtfQUA/s640/ca2.PNG
Step3:- Now Write the code for captcha control in source file.
see it:-
Description: http://3.bp.blogspot.com/-it2AlTPYQN0/UCLV9v2sZ4I/AAAAAAAAAnc/4CImUos-Zzw/s640/ca3.PNG

Step4:-  Now Drag and Drop Text-box,Button, Label and Validation control control on Default.aspx page from the Toolbox.which is shown below:-
see it:-
Description: http://4.bp.blogspot.com/-vSY5m_qzngA/UCLYZXXs4UI/AAAAAAAAAoA/iMhYV9IlSlk/s640/ca4.PNG

Step5:- Now Double click on Button control(Verify) and write the following code.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        captcha1.ValidateCaptcha(TextBox2.Text.Trim());
        if (captcha1.UserValidated)
        {
          Label1.ForeColor = System.Drawing.Color.Green;
          Label1.Text = "You have Entered Valid Captcha Characters";
        }
        else
        {
            Label1.ForeColor = System.Drawing.Color.Red;
            Label1.Text = "You have Entered InValid Captcha Characters please Enter again";
        }
    }
}
see it:-
Description: http://2.bp.blogspot.com/-aLTTEvbO42k/UCLZjYmfaoI/AAAAAAAAAoI/ZyJpJP7uMeE/s640/ca5.PNG

Step6:- Now open the web.config file and write the following code.
?
1
2
3
<httphandlers>
   <add path="CaptchaImage.axd" type="MSCaptcha.CaptchaImageHandler, MSCaptcha "verb="GET">
  </add></httphandlers>
see it:-
Description: http://1.bp.blogspot.com/-dktLzI76bTI/UCLalyNSl8I/AAAAAAAAAoQ/BLF6JY7gkgE/s640/ca6.PNG

Step7:- Run the Application (press F5).
see
OUTPUT:-
·                     when we Entered correct captcha image In Text-Box and click Verify Button.
Description: http://2.bp.blogspot.com/-TpoPfoLSssY/UCLcF8XHkJI/AAAAAAAAAoY/1j8u3CSS-Zc/s640/CA7.PNG

·                     when we Entered Incorrect captcha image In Text-Box and click Verify Button.
Description: http://3.bp.blogspot.com/-xYv17TyOj7E/UCLcWqz-u5I/AAAAAAAAAog/9gwtOFwPmVA/s640/ca77.PNG


1 comment:

  1. I’m thoroughly impressed with your expertise blog. You are decide to helping us…..this is very good initiative. Thank you very much.
    You can also visit:
    BULK SMS SERVICE PROVIDER IN DELHI
    VODAFONE BULK SMS SERVICE
    BULK SMS IN KUWAIT

    ReplyDelete