Create Mathematical Captcha In ASP.NET MVC

In the previous article Create Captcha In ASP.NET MVC, I have explained that how to create Captcha, what is it, and why it’s used. In this article, I will explain that how to create Mathematical Captcha to ASP.NET MVC project.

Well, it is most similar to normal Captcha. There is a minor difference between them.

Note: The controller code and the Success view are the same as in the previous article. The change is only in the Index view.

Here is the View

The change is, you just need to remove @Html.Captcha(5) and add@Html.MathCaptcha(). It will display Mathematical Captcha.

@using CaptchaMvc.HtmlHelpers;
@{
    ViewBag.Title = "Home Page";
}
@using (Html.BeginForm("ValidateCaptcha", "Home", FormMethod.Post))
{
    <div class="container" id="CaptchaDiv">
        <h3>Captcha Demo</h3>
        <div class="row">
            <div class="col-lg-4 form-group">
                @Html.MathCaptcha()
                @*@Html.Captcha(5)*@
                <br />
                <span style="color:red">@ViewBag.error</span>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-4">
                <input type="submit" class="btn btn-primary" id="btnSubmit" value="Submit" />
            </div>
        </div>
    </div>
}

Output

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories