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: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOUGdvZzET_bBfcfVDyuUbAguosjwkuG6OBfxmKoNwdEl0UfiCfUBy-q7IAn-H4GeSzMG1JdRf6of8IZJhUjQM0JO78RJIriam7MOIzazr61mLKzHm6_MyznLux3pqEJhqR0-gknsOF6q0/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: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgE-2GgfSyH1CwhEGLsLjOR-RW0brqt3qB2qzrsuJaSm9Z6WRCu-jGReC0IL1X0_3RKAUWcZHhodvrBmqxTZb5VH4nA3JrQ5qcIT91pt6f9r8EYexbMDa4CIThxg3jljkSdqNbdWeKkPToZ/s640/ca2.PNG
Step3:- Now Write the code for captcha control in source file.
see it:-
Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiC63mamltrg3fR9-UnOnJYq2Gn2wJdKCt4QteRfJ5e_ynHX4-bPz5GXXv6FW1BGofNpN2iHofYGzDUbTrGpTBENppi-Q1DuKKsQHQkPrn2jMzeKkfdJKrf2ZRhEasbg2oio2diljTCIoCa/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: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6-WP9YL6YhkcPujHEMiONBHnyu8DnstjjecMPj6pioSFHikROrKPCvzYVZXyYhvZUZAYz_yio0EYCv3xcsjG2l9_nsob8Q3WPpZHffjZuwyKrhdzbd_74FXtAHyO1QjSHtsmxvo6rfIdo/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: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjetxqjv0m19DQvBe3ndUh7pDTz_BJMomFIA0oL3GzB3pWAvFfvaUSEjca-RYP56sZnRP3WweB9e1DUTTJYHodFySOcnxX6RNrIt5qqw-YLvMRNEZhDvTyyGjUxAp1UghUqo2nOWz9-pdLq/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: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG055lMeG7I5qZg2v0y7I1zYP_oCJdlsQEoJxFe1Nw-V9d5-C5YXJ2Y2zbgpw8k0ac53bJRZnroEdcvdhT9sa3ZaVP3CSoFZqnsV9nX7YJeWKRJK0bpqO9rexTZyhj_ECVJzMNDcJcTHun/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: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj50LaGG8Q2zna-42htvBE7E48DwS6-aoxtWK45Pqxgi5mNTWn9RpZQlWYwjLPqEskdu8l5fpK7Y14Jsofrfl1AL_MvpdNrweWwuCimYoVEpjda8DETTGovxQgOfcu8NKNXLR9EDoLwZM8Z/s640/CA7.PNG

·                     when we Entered Incorrect captcha image In Text-Box and click Verify Button.
Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSt5ZxWL4j3F8X5UmIM4oQbmSjNwSriZDeJbLNSuYIXmHnHz9PKU507UbROByd-WvM3Fme2tfmaPNEmFYAh2P9mdWclVo_zoJv-aRIyGBGyVY3xxT3w0JhtChB7VAZ998SgqK6dUQnf15_/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