Last active
February 17, 2018 12:32
-
-
Save MoienTajik/52df500c02526017c356056eec7f2f71 to your computer and use it in GitHub Desktop.
Using Google reCAPTCHA in ASP.NET MVC - reCAPTCHA Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class GoogleCaptchaHelper | |
{ | |
public static IHtmlString GoogleCaptcha(this HtmlHelper helper) | |
{ | |
const string publicSiteKey = SiteSettings.GoogleRecaptchaSiteKey; | |
var mvcHtmlString = new TagBuilder("div") | |
{ | |
Attributes = | |
{ | |
new KeyValuePair<string, string>("class", "g-recaptcha"), | |
new KeyValuePair<string, string>("data-sitekey", publicSiteKey) | |
} | |
}; | |
const string googleCaptchaScript = "<script src='https://www.google.com/recaptcha/api.js'></script>"; | |
var renderedCaptcha = mvcHtmlString.ToString(TagRenderMode.Normal); | |
return MvcHtmlString.Create($"{googleCaptchaScript}{renderedCaptcha}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment