Skip to content

alisherdavronov/Recaptcha2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Recaptcha2

ASP.NET MVC 5 widget for google's recaptcha

Usage

  1. Register in google's recaptcha 2 and get site key and secret.

  2. Add site key and secret into web.config:

<configuration>
  <appSettings>
    <add key="Recaptcha2SiteKey" value="{Put here site key}"/>
    <add key="Recaptcha2Secret" value="{Put here secret}"/>
    ...
  1. Add Recaptcha2 class to your ASP.NET MVC 5 project.

  2. Add Recaptcha2 to your forms view:

@using Recaptcha2
...
@using (Html.BeginForm()) 
{
...
        <div class="form-group">
            @Html.Label("Code", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.Recaptcha2()
                @Html.ValidationMessage("g-recaptcha-response", "", new { @class = "text-danger" })
            </div>
        </div>

*No need to create a property in model for captcha code.

  1. Add ValidateRecaptcha2 attribute to your controller's post action:
        [HttpPost]
        [ValidateAntiForgeryToken]
        [ValidateRecaptcha2(ErrorMessage = @"Recaptcha is required")]

Have fun.

About

asp.net mvc 5 widget for google's recaptcha 2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages