How to Add a Captcha Image in ASP.NET Application

By
There are some steps to Add Captcha image in Asp.NET Application. You can download whole application from below link.You can easily add this captcha image to your Asp.Net Application Without facing any problem. You can add another captcha code also in any asp.net application from here.Both captcha codes will be provided full security to your asp.net application. Please follow these  steps one by one which are 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:-
MSCaptcha.dll
Step2:-Now Open Solution Explorer -->Add new Folder(Bin)->open the captcha.dll file->copy all the file -> Now paste it in the Bin Folder.
see it:-
paste_dll

Step3:- Now Write the code for captcha control in Source file as shown below:
see it:-
design_mode

Step4:-  Now Drag and Drop Text-box,Button, Label and Validation controls on Default.aspx page from the Toolbox.which is as shown below:-
see it:-
validation_control

Step5:- Now Double click on Button control(Verify) and write the following code.

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:-

c#_codes

Step6:- Now open the web.config file and write the following codes as shown below.
see it:-

web.config

Step7:- Run the Application (press F5).
see it:
OUTPUT:-
  • when we Enter the  correct captcha image In the  Text-Box and click Verify Button,then we see following output:-
output

  • when we Enter the Incorrect captcha image In the  Text-Box and Click Verify Button,then we see following output :
output
Step8:-If you want to run this whole web application directly on your visual studio then follow below steps which are given below:-
  •  First Download this whole application from bottom and Extract it-->Copy this whole file (cltr+c).
  •  Now open your visual studio --> File --.New --.website -->Select ASP.NET Empty website -->OK -->Now open Solution Explorer -->Right click on project -->Paste this whole application which you have copied previously. 
  • Now Run the application-->then you can run this application successfully.
  • If you are facing problem-->Download captcha.dll file from step 1 --> Extract it and copy all dll files -->open solution explorer -->Past this dll file in bin Folder.
  • Now again run (press F5) then it will definitely work.
Please share this application with your friends so that it may helpful to others also.If any problem ask frequently.I will solve your doubt definitely.
 Download whole attached application.
         DOWNLOAD

48 comments:

  1. the characters matching with the captcha image characters are not case sensitive.I need to make a case sensitive match. Can some one help.

    ReplyDelete
  2. thanx my friends, I am comming soon for new post.many times i have not written any post because i was doing training from C-dac in SECURITY Domain. Now i finished it now again i will write some good post which is helpful for learner(YOU).

    ReplyDelete
    Replies
    1. i am still not getting image on web page at local host

      Delete
  3. code is perfect.. bt itz not displaying the catcha image and so I cnt even enter the text.. plz help.. do revert back on steffi.aiesec@gmail.com

    ReplyDelete
  4. This code is not working in Framework 3.5. Is there any updation to be done in the code?
    Without this captcha my main project is not working. Kindly help me to solve the problem.

    ReplyDelete
  5. hii,

    im getting this error

    in default.aspx file

    element CaptchaControl is not a known element

    ReplyDelete
  6. Goodone I'll try it and use it on my website www.jokeshindi.com

    ReplyDelete
  7. Warning 1 Unable to update auto-refresh reference 'mscaptcha.dll'. Cannot find assembly 'D:\Documents and Settings\Administrator\Desktop\mscaptcha\MSCaptcha.dll'. C:\Users\HRAMAN\Documents\Visual Studio 2012\captcha\Bin\mscaptcha.dll.refresh captcha

    ReplyDelete
  8. if you are using my application,then first delete all mscaptcha.dll file from bin folder.close your application,after that open -->go bin folder and paste the all mscaptcha.dll file from step 1. you can use captcha image on your website without dll file Read it:-
    http://www.msdotnet.co.in/2013/09/how-to-create-captcha-image-without-dll.html

    ReplyDelete
  9. how to create a newfolder ,if a am creating the bin folder it is already exist how to I create a bin folder

    ReplyDelete
  10. iMAGE GENERATION IS NOT TAKING PLACE....

    ReplyDelete
  11. Error Creating Control - captcha1Unknown server tag 'rsv:CaptchaControl'...This error is coming..what is the solution???

    ReplyDelete
    Replies
    1. hi priya , try again ,otherwise download whole application from below and run directly on your visual studio .it will definitely work.........

      Delete
  12. Its working......!
    thanx :-)

    ReplyDelete
  13. My Captcha Image is Not displying i use same code..........
    and also try in different browser also............!!

    help me............

    ReplyDelete
    Replies
    1. it is working try again carefully...........

      Delete
  14. "TagePrefix" attribute missing and unknown server tag 'rsv:CaptchaControl '
    help me

    ReplyDelete
    Replies
    1. you have not follow each steps correctly.see step 3 carefully ,try again with fresh application.it will work definitely.if you face problem again,contact me through contact form.

      Delete
  15. SIR please upload wpf tutorial with examples

    ReplyDelete
  16. it is giving error
    Unrecognized configuration section compilation.

    ReplyDelete
  17. hi pankaj ! you have not follow each step carefully.Any way Follow another way
    1.) download whole application from bottom and extract it.-->open folder -->copy all files
    2.) open your visual studio -->file --.New -->Website-->select ASP.NET Empty website -->ok
    3.) open your solution explorer -->Right click on project --> paste the all file (which you have copied previous).
    Now run the application it will work definitely.Please inform me if you run this application successfully..

    ReplyDelete
  18. Hi ,
    I am using MsCaptcha for validation on my website but captcha image is not always displayed when website is hosted on cloud.It displayes a blank image with a red cross on left side of image ,if I right click on image and choose the option show picture then the image is displayed but I have to do this 2-3 times in order to see the image.Please help me out with it

    ReplyDelete
    Replies
    1. Hi venkat !
      1.) set your AutoEventWireup properties="true"
      2.) paste captcha dll file in bin folder
      it may be helpful for you.

      Delete
  19. Hi,
    Thanks for your reply I already set the AutoEventWireup=true.But no use the captcha appears on a random basis.
    It shows broken image several times then we have to refresh the 3-4 times then captcha appears automatically.
    I am using the captcha image in the Blog section.Please help me out with it.

    ReplyDelete
    Replies
    1. Hi Venkat ! You can use different method to generate captcha image from below link:
      http://www.msdotnet.co.in/2013/09/how-to-create-captcha-image-without-dll.html

      Delete
  20. The error says
    The type or namespace name 'MSCaptcha' could not be found in the global namespace (are you missing an assembly reference?)

    Help me resolve this please

    ReplyDelete
    Replies
    1. hi samia ! go step 3 and see ,i have registered Assembly =MsCaptcha ; then it will work......

      Delete
  21. Thank you boss .. its working .. :)

    ReplyDelete
  22. your article is very help full .. please make more user friendly ..

    ReplyDelete
  23. Hi Sir Please See I have got error
    " WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive). "

    ReplyDelete
  24. Thanks a lot. it works very fine. its too simple to use also. I appreciate your work. :)

    ReplyDelete
  25. Thanks a lot. It works very fine. I appreciate your work. :)

    ReplyDelete
  26. Hi this code work when i work local server if iam upload in public server this code not work show broken image after hosting how can i solve plz send replay to rizwan.thesohoy@gmail.com
    Thank You
    Rizwan.

    ReplyDelete
  27. Hi, The code works perfactly on my local system but does not desplay image when run on the server. What can be the issue?

    ReplyDelete
  28. what is the issue the captcha image doesnt get displayed when it is hosted on server pls reply....

    ReplyDelete
  29. When i copy and paste application then following errors comes

    HTTP Error 500.23 - Internal Server Error
    An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.

    Most likely causes:
    This application defines configuration in the system.web/httpHandlers section.

    ReplyDelete
    Replies
    1. Hi Purusottam, If you are getting error ,Follow each steps on your visual studio .You can easily remove your error....

      Delete
  30. Hello friend pleas check out link....

    http://www.codescratcher.com/asp-net/captcha-image-using-c-asp-net/

    ReplyDelete
  31. Hi I downloaded your application and run it as it is. It is still giving the error
    1. Could not load file or assembly 'MSCaptcha' or one of its dependencies. The system cannot find the file specified.
    2. Unknown server tag 'rsv:CaptchaControl'.

    and a warning:
    Element 'CaptchaControl' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing.

    I am using Visual Studio 2010 Express and .NET Framework 4.5

    ReplyDelete
  32. add reference of MSCaptcha.dll then at will work fine......

    ReplyDelete
  33. Hi,

    Hi i have downloaded your captcha image project it is running on localhost but it is not showing the captcha image after hosting on server.
    Please do help ASAP.

    Regards,
    Nilesh

    ReplyDelete
  34. Hi I have same code and work perfectly fine only in root directory. Can any one tell me, what should I do to run this in folder not root directory?

    ReplyDelete
  35. Captcha image is nt gettng????

    ReplyDelete
  36. After running, this was what i faced as the current problem with my App:

    "
    HTTP Error 500.23 - Internal Server Error
    An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode. "

    Any help? Thanks in advance

    ReplyDelete
  37. hiii....
    I am not able to download captcha file from your dropbox link plz help me.
    It was showing error---> "file not found""dropbox-404"

    ReplyDelete

Powered by Blogger.