2010-10-03 62 views
1

我在我的MVC项目中使用这种this Recaptcha方法,但它不验证严格1.0 DOCTYPE。ASP.Net MVC Recaptcha和严格Doctype

任何人都可以帮忙吗?

谢谢

+0

你想要什么帮助? – roryf 2010-10-03 16:39:20

+0

让它通过严格的文档类型验证 – Jon 2010-10-03 16:41:32

+0

我刚才看了看源代码,它使用了一个iframe,所以它不会传递。耻辱。 – Jon 2010-10-03 17:56:17

回答

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

我会通过NuGet软件包参考推荐Microsoft Web Helpers库。

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

+0

它是否生成有效的HTML? – Jon 2011-01-25 10:16:50

+0

我得到3个错误... [编辑]代码如下:http://www.codeupload.com/3782 – kapsi 2011-02-03 10:01:39