/// <summary> /// Renders the recaptcha HTML in an MVC view. It is an extension method to the <see cref="System.Web.Mvc.HtmlHelper"/> class. /// </summary> /// <param name="htmlHelper">The <see cref="System.Web.Mvc.HtmlHelper"/> object to which the extension is added.</param> /// <param name="publicKey">Sets the public key of recaptcha.</param> /// <param name="theme">Sets the theme of recaptcha.</param> /// <param name="language">Sets the language of recaptcha. If no language is specified, the language of the current UI culture will be used.</param> /// <param name="tabIndex">Sets the tab index of recaptcha.</param> /// <param name="dataType">Sets the data type of recaptcha.</param> /// <param name="dataSize">Sets the size of recaptcha.</param> /// <param name="useSsl">Sets the value to the UseSsl property.</param> /// <param name="apiVersion">Determines the version of the reCAPTCHA API.</param> /// <returns>Returns an instance of the IHtmlString type.</returns> public static IHtmlString Recaptcha( this HtmlHelper htmlHelper, string publicKey = "{recaptchaPublicKey}", RecaptchaTheme theme = RecaptchaTheme.Red, string language = null, int tabIndex = 0, RecaptchaDataType?dataType = null, RecaptchaDataSize?dataSize = null, SslBehavior useSsl = SslBehavior.SameAsRequestUrl, string apiVersion = "{recaptchaApiVersion}") { IRecaptchaHtmlHelper rHtmlHelper = null; string version = RecaptchaKeyHelper.ParseKey(apiVersion); if (version != "2") { rHtmlHelper = new RecaptchaHtmlHelper(publicKey, theme, language, tabIndex, useSsl); } else { rHtmlHelper = new Recaptcha2HtmlHelper(publicKey, theme, language, tabIndex, dataType, dataSize, useSsl); } var writer = new HtmlTextWriter(new StringWriter()); writer.Write(rHtmlHelper.ToString()); return(htmlHelper.Raw(writer.InnerWriter.ToString())); }
/// <summary> /// Renders the recaptcha HTML in an MVC view. It is an extension method to the <see cref="System.Web.Mvc.HtmlHelper"/> class. /// </summary> /// <param name="htmlHelper">The <see cref="System.Web.Mvc.HtmlHelper"/> object to which the extension is added.</param> /// <param name="publicKey">Sets the public key of recaptcha.</param> /// <param name="theme">Sets the theme of recaptcha.</param> /// <param name="language">Sets the language of recaptcha. If no language is specified, the language of the current UI culture will be used.</param> /// <param name="tabIndex">Sets the tab index of recaptcha.</param> /// <param name="dataType">Sets the data type of recaptcha.</param> /// <param name="dataSize">Sets the size of recaptcha.</param> /// <param name="useSsl">Sets the value to the UseSsl property.</param> /// <param name="apiVersion">Determines the version of the reCAPTCHA API.</param> /// <returns>Returns an instance of the IHtmlString type.</returns> public static IHtmlString Recaptcha( this HtmlHelper htmlHelper, string publicKey = "{recaptchaPublicKey}", RecaptchaTheme theme = RecaptchaTheme.Red, string language = null, int tabIndex = 0, RecaptchaDataType? dataType = null, RecaptchaDataSize? dataSize = null, SslBehavior useSsl = SslBehavior.SameAsRequestUrl, string apiVersion = "{recaptchaApiVersion}") { IRecaptchaHtmlHelper rHtmlHelper = null; string version = RecaptchaKeyHelper.ParseKey(apiVersion); if (version != "2") { rHtmlHelper = new RecaptchaHtmlHelper(publicKey, theme, language, tabIndex, useSsl); } else { rHtmlHelper = new Recaptcha2HtmlHelper(publicKey, theme, language, tabIndex, dataType, dataSize, useSsl); } var writer = new HtmlTextWriter(new StringWriter()); writer.Write(rHtmlHelper.ToString()); return htmlHelper.Raw(writer.InnerWriter.ToString()); }
/// <summary> /// Renders the recaptcha HTML in an MVC view. It is an extension method to the <see cref="System.Web.Mvc.HtmlHelper"/> class. /// </summary> /// <param name="htmlHelper">The <see cref="System.Web.Mvc.HtmlHelper"/> object to which the extension is added.</param> /// <param name="siteKey">Sets the site key of recaptcha.</param> /// <param name="renderApiScript">Determines if the API script call is to be rendered.</param> /// <param name="theme">Sets the theme of recaptcha.</param> /// <param name="language">Sets the language of recaptcha. If no language is specified, the language of the current UI culture will be used.</param> /// <param name="tabIndex">Sets the tab index of recaptcha.</param> /// <param name="size">Sets the size of recaptcha.</param> /// <param name="useSsl">Sets the value to the UseSsl property.</param> /// <param name="apiVersion">Determines the version of the reCAPTCHA API.</param> /// <returns>Returns an instance of the IHtmlString type.</returns> public static IHtmlContent RecaptchaWidget( this IHtmlHelper htmlHelper, string siteKey = null, bool renderApiScript = true, RecaptchaTheme?theme = null, string language = null, int?tabIndex = null, RecaptchaSize?size = null, RecaptchaSslBehavior?useSsl = null, string apiVersion = null) { var config = RecaptchaConfigurationManager.GetConfiguration(); string ver; if (!string.IsNullOrEmpty(apiVersion)) { ver = apiVersion; } else { ver = config.ApiVersion; } if (ver == null || ver == "2") { var rHtmlHelper = new Recaptcha2HtmlHelper(siteKey ?? config.SiteKey); return(new HtmlString(rHtmlHelper.CreateWidgetHtml(renderApiScript, theme != null ? (RecaptchaTheme)theme : config.Theme, language ?? config.Language, tabIndex != null ? (int)tabIndex : 0, size != null ? (RecaptchaSize)size : config.Size, useSsl != null ? (RecaptchaSslBehavior)useSsl : config.UseSsl))); } else { throw new InvalidOperationException("The API version is either invalid or not supported."); } }
/// <summary> /// Renders the recaptcha HTML in an MVC view. It is an extension method to the <see cref="System.Web.Mvc.HtmlHelper"/> class. /// </summary> /// <param name="htmlHelper">The <see cref="System.Web.Mvc.HtmlHelper"/> object to which the extension is added.</param> /// <param name="siteKey">Sets the site key of recaptcha.</param> /// <param name="language">Sets the language of recaptcha. If no language is specified, the language of the current UI culture will be used.</param> /// <param name="useSsl">Sets the value to the UseSsl property.</param> /// <param name="apiVersion">Determines the version of the reCAPTCHA API.</param> /// <returns>Returns an instance of the IHtmlString type.</returns> public static IHtmlContent RecaptchaApiScript( this IHtmlHelper htmlHelper, string siteKey = null, string language = null, RecaptchaSslBehavior?useSsl = null, string apiVersion = null) { var config = RecaptchaConfigurationManager.GetConfiguration(); string ver; if (!string.IsNullOrEmpty(apiVersion)) { ver = apiVersion; } else { ver = config.ApiVersion; } if (ver == null || ver == "2") { var rHtmlHelper = new Recaptcha2HtmlHelper(siteKey ?? config.SiteKey); return(new HtmlString(rHtmlHelper.CreateApiScripttHtml(language ?? config.Language, useSsl != null ? (RecaptchaSslBehavior)useSsl : config.UseSsl))); } else { throw new InvalidOperationException("The API version is either invalid or not supported."); } }
/// <summary> /// Redners the HTML output. This method is automatically called by ASP.NET during the rendering process. /// </summary> /// <param name="output">The output object to which the method will write HTML to.</param> /// <exception cref="InvalidOperationException">The exception is thrown if the public key is not set.</exception> protected override void RenderContents(HtmlTextWriter output) { if (this.DesignMode) { output.Write("<p>Recaptcha API Script Control</p>"); } else { if (ApiVersion == null || ApiVersion == "2") { var htmlHelper = new Recaptcha2HtmlHelper(this.SiteKey); output.Write(htmlHelper.CreateApiScripttHtml(Language, UseSsl)); } else { throw new InvalidOperationException("The API version is either invalid or not supported."); } } }
/// <summary> /// Redners the HTML output. This method is automatically called by ASP.NET during the rendering process. /// </summary> /// <param name="output">The output object to which the method will write HTML to.</param> /// <exception cref="InvalidOperationException">The exception is thrown if the public key is not set.</exception> protected override void RenderContents(HtmlTextWriter output) { if (this.DesignMode) { output.Write("<p>Recaptcha Control</p>"); } else { IRecaptchaHtmlHelper htmlHelper = null; string apiVersion = RecaptchaKeyHelper.ParseKey(ApiVersion); if (apiVersion != "2") { htmlHelper = new RecaptchaHtmlHelper(this.PublicKey, this.Theme, this.Language, this.TabIndex, this.UseSsl); } else { htmlHelper = new Recaptcha2HtmlHelper(this.PublicKey, this.Theme, this.Language, this.TabIndex, this.DataType, this.DataSize, this.UseSsl); } output.Write(htmlHelper.ToString()); } }