Spamming is a common issue with online web-based applications these days. Especially in those applications and websites which are open to the public, it is hard to find and fight spam. Even big websites such as GitHub have been suffering from such issues.
Hence, it is mandatory to use some form of mechanism to avoid and fight spam in an automated manner. The globally accepted mechanism to fight spamming is CAPTCHA and in this article, we are discussing an easy way to use and implement captcha in ASP.Net.
What is Captcha?
Before we implement, it is important to understand as to what Captcha is. It is a system or computer program, which is designed to distinguish between human and machine based input. This is intended for thwarting spam and automated extraction of data from websites. This show some form of data in images and users are required to enter the same in textbox to get their request accepted on a webpage.
Implementing Captcha in ASP.NET
We always believe that one should not put efforts in trying to reinvent the wheel. Hence, here are the easy steps to implement Captcha in ASP.Net in a highly effective manner:
- First of all, download the MSCaptcha.dll from this link (MsCaptcha Rar).
- Extract the dll/assembly using WinZip or WinRar.
- Now open the ASP.Net project in which you want to add Captcha in Visual Studio.
- Right click on the project and select ‘Add Reference’.
- Browse and select the downloaded Captcha dll.
- You will find that the reference of it gets added in the project.
- Next step is added, add this key into the Web.Config file.
12<add verb="GET" type="MSCaptcha.CaptchaImageHandler, MSCaptcha"path="CaptchaImage.axd" />
- This will add a captcha control to project. Now on the page where you want to implement captcha, register it using following syntax:
1<%@ Register Assembly="MSCaptcha" Namespace="MSCaptcha" TagPrefix="cc1" %>
- Now use Captcha in code directly with the code as shown below:
1234<cc1:CaptchaControl ID="ChewCode" runat="server" CaptchaMinTimeout="5"CaptchaMaxTimeout="240" FontColor = "#00000" CaptchaBackgroundNoise="Low"CaptchaLength="5" CaptchaHeight="60" CaptchaWidth="200"CaptchaLineNoise="None" />
So with this, you have added captcha into your ASP.Net page using C#. We hope this will help you fight spam in a better manner.
Drop your queries below.