答案 0 :(得分:1)
我会通过NuGet包引用推荐Microsoft Web Helpers库。
答案 1 :(得分:0)
创建自己的控件。正如您在RecaptchaControl的RenderContents方法中所看到的,它使用iframe。 iframe不符合HTML严格要求,因此您必须使用HTML对象标记。
protected override void RenderContents(HtmlTextWriter output)
{
output.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript");
output.RenderBeginTag(HtmlTextWriterTag.Script);
output.Indent++;
output.WriteLine("var RecaptchaOptions = {");
output.Indent++;
output.WriteLine("theme : '{0}',", this.theme ?? string.Empty);
if (this.customThemeWidget != null)
{
output.WriteLine("custom_theme_widget : '{0}',", this.customThemeWidget);
}
output.WriteLine("tabindex : {0}", this.TabIndex);
output.Indent--;
output.WriteLine("};");
output.Indent--;
output.RenderEndTag();
output.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript");
output.AddAttribute(HtmlTextWriterAttribute.Src, this.GenerateChallengeUrl(false), false);
output.RenderBeginTag(HtmlTextWriterTag.Script);
output.RenderEndTag();
output.RenderBeginTag(HtmlTextWriterTag.Noscript);
output.Indent++;
output.AddAttribute(HtmlTextWriterAttribute.Src, this.GenerateChallengeUrl(true), false);
output.AddAttribute(HtmlTextWriterAttribute.Width, "500");
output.AddAttribute(HtmlTextWriterAttribute.Height, "300");
output.AddAttribute("frameborder", "0");
output.RenderBeginTag(HtmlTextWriterTag.Iframe); // Change this to object HTML tag
output.RenderEndTag();
output.WriteBreak();
output.AddAttribute(HtmlTextWriterAttribute.Name, "recaptcha_challenge_field");
output.AddAttribute(HtmlTextWriterAttribute.Rows, "3");
output.AddAttribute(HtmlTextWriterAttribute.Cols, "40");
output.RenderBeginTag(HtmlTextWriterTag.Textarea);
output.RenderEndTag();
output.AddAttribute(HtmlTextWriterAttribute.Name, "recaptcha_response_field");
output.AddAttribute(HtmlTextWriterAttribute.Value, "manual_challenge");
output.AddAttribute(HtmlTextWriterAttribute.Type, "hidden");
output.RenderBeginTag(HtmlTextWriterTag.Input);
output.RenderEndTag();
output.Indent--;
output.RenderEndTag();
}