ASP.Net MVC Recaptcha 和严格文档类型

发布于 2024-09-26 01:57:55 字数 224 浏览 2 评论 0原文

我正在使用这个 这个 我的 MVC 项目中的 Recaptcha 方法,但它无法验证 Strict 1.0 DOCTYPE。

有人可以帮忙吗?

谢谢

I am using this this Recaptcha approach in my MVC project however it does not validate to Strict 1.0 DOCTYPE.

Can anyone help?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只是在用心讲痛 2024-10-03 01:57:55

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

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

I would recommend the Microsoft Web Helpers library through NuGet package reference.

Here is a blog post: http://www.dotnetcurry.com/ShowArticle.aspx?ID=611

我三岁 2024-10-03 01:57:55

创建您自己的控件。正如您在 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();
}

Create your own control. As you can see in the RenderContents method of the RecaptchaControl, it use an iframe. Iframe are not HTML strict compliant, thus you have to use a HTML object tag.

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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文