Captcha 4.2.0
The BotDetect ASP.NET CAPTCHA NuGet package has been added to your project.
1. Captcha integration instructions
2. ASP.NET Captcha code examples download
3. BotDetect Captcha documentation
- CAPTCHA INTEGRATION INSTRUCTIONS
To show a Captcha challenge on the form and check user input during form submission:
ASP.NET MVC
In View code: import the BotDetect namespace, include BotDetect styles in page
, create a MvcCaptcha object and pass it to the Captcha HtmlHelper: @using BotDetect.Web.Mvc;
[...]
<link href="@BotDetect.Web.CaptchaUrls.Absolute.LayoutStyleSheetUrl" rel="stylesheet" type="text/css" />
</head>
[...]
@{ MvcCaptcha exampleCaptcha = new MvcCaptcha("ExampleCaptcha"); }
@Html.Captcha(exampleCaptcha)
@Html.TextBox("CaptchaCode")
Exclude BotDetect paths from ASP.NET MVC Routing:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// BotDetect requests must not be routed
routes.IgnoreRoute("{*botdetect}", new { botdetect = @"(.*)BotDetectCaptcha\.ashx" });
Mark the protected Controller action with the CaptchaValidation attribute to include Captcha validation in ModelState.IsValid checks:
using BotDetect.Web.Mvc;
[HttpPost]
[AllowAnonymous]
[CaptchaValidation("CaptchaCode", "ExampleCaptcha", "Incorrect CAPTCHA code!")]
public ActionResult ExampleAction(ExampleModel model)
{
if (!ModelState.IsValid)
{
// TODO: Captcha validation failed, show error message
}
else
{
// TODO: Captcha validation passed, proceed with protected action
}
Detailed ASP.NET MVC integration instructions can be found at http://captcha.com/doc/aspnet/howto/asp.net-mvc-captcha.html.
ASP.NET Web Pages
On the ASP.NET form you want to protect against bots, add:
@{ Captcha exampleCaptcha = new Captcha("ExampleCaptcha"); exampleCaptcha.UserInputID = "CaptchaCode"; } When the form is submitted, the Captcha validation result must be checked:
@if ((Request.HttpMethod == "POST")) { bool isHuman = exampleCaptcha.Validate(); if (isHuman) { Correct! } else { Incorrect! } } Detailed ASP.NET Web Pages integration instructions can be found at http://captcha.com/doc/aspnet/howto/asp.net-webpages-captcha.html.
ASP.NET WebForms
On the ASP.NET form you want to protect against bots, add:
<BotDetect:WebFormsCaptcha ID="ExampleCaptcha" runat="server" />
<asp:TextBox ID="CaptchaCodeTextBox" runat="server" />
When the form is submitted, the Captcha validation result must be checked:
if (IsPostBack)
{
// validate the Captcha to check we're not dealing with a bot
bool isHuman = ExampleCaptcha.Validate(CaptchaCodeTextBox.Text);
CaptchaCodeTextBox.Text = null; // clear previous user input
if (!isHuman)
{
// TODO: Captcha validation failed, show error message
}
else
{
// TODO: Captcha validation passed, proceed with protected action
}
}
Detailed ASP.NET WebForms integration instructions can be found at http://captcha.com/doc/aspnet/howto/asp.net-webforms-captcha.html.
- ASP.NET CAPTCHA CODE EXAMPLES DOWNLOAD
CAPTCHA code examples (ASP.NET WebForms integration examples, ASP.NET MVC integration examples, BotDetect configuration examples - with both C# and VB.NET and ASPX/Razor variants), as well as equivalents for older .NET framework versions and additional resources are included in the BotDetect setup package which can be downloaded from:
http://captcha.com/captcha-download.html?version=aspnet.
- BOTDETECT CAPTCHA DOCUMENTATION
The full index of available BotDetect ASP.NET CAPTCHA documentation can be found at:
No packages depend on Captcha.
Version | Downloads | Last updated |
---|---|---|
4.4.2 | 26 | 02/14/2024 |
4.4.1 | 23 | 02/14/2024 |
4.4.0 | 23 | 02/14/2024 |
4.3.3 | 18 | 02/14/2024 |
4.3.2 | 43 | 02/14/2024 |
4.3.1 | 22 | 02/14/2024 |
4.3.0 | 37 | 02/14/2024 |
4.2.0 | 24 | 02/10/2020 |
4.1.0 | 17 | 02/14/2024 |
4.0.1 | 36 | 02/14/2024 |
3.0.18 | 18 | 02/14/2024 |
3.0.17 | 42 | 02/14/2024 |
3.0.16 | 19 | 02/14/2024 |
3.0.15.1 | 19 | 02/14/2024 |
3.0.15 | 20 | 02/14/2024 |
3.0.14.10 | 25 | 02/14/2024 |
3.0.14.9 | 22 | 02/14/2024 |
3.0.14.7 | 19 | 02/14/2024 |
3.0.14.6 | 18 | 02/14/2024 |