ASP.Net MVC Recaptcha和Strict Doctype

时间:2010-10-03 16:31:02

标签: asp.net asp.net-mvc asp.net-mvc-2 recaptcha

我在我的MVC项目中使用了这个this Recaptcha方法,但它没有验证严格的1.0 DOCTYPE。

有人可以帮忙吗?

由于

2 个答案:

答案 0 :(得分:1)

我会通过NuGet包引用推荐Microsoft Web Helpers库。

这是一篇博文:http://www.dotnetcurry.com/ShowArticle.aspx?ID=611

答案 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();
}