使用 ASP.NET MVC 的 ASP.NET CAPTCHA 控件示例出现问题

发布于 2024-08-03 06:07:24 字数 528 浏览 2 评论 0原文

我正在尝试使用以下 A CAPTCHA Server Control for ASP.NET - 作者:Jeff ASP.NET MVC 站点中的 Atwood。提交表单时,自定义控件似乎没有验证。

有人使用 ASP.NET MVC 对此示例进行过任何工作吗?

我使用的基本代码如下:

<% using (Html.BeginForm()) { %>
<CaptchaControl:CaptchaControl ID="CaptchaControl" Name="Security" runat="server"></CaptchaControl:CaptchaControl>
<input type="submit" value="Send Message" />
<% } %>

I am trying to use the following A CAPTCHA Server Control for ASP.NET - by Jeff Atwood within an ASP.NET MVC site. The custom control doesn't seem to be validating when the form is submitted.

Is there anyone who has done any work with this sample using ASP.NET MVC?

The basic code I am using is as follows:

<% using (Html.BeginForm()) { %>
<CaptchaControl:CaptchaControl ID="CaptchaControl" Name="Security" runat="server"></CaptchaControl:CaptchaControl>
<input type="submit" value="Send Message" />
<% } %>

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

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

发布评论

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

评论(3

凤舞天涯 2024-08-10 06:07:24

确实不建议对 ASP.Net MVC 站点使用 ASP.Net 服务器控件。 ASP.Net MVC 不像常规 ASP.Net 那样执行页面生命周期。服务器控件可以呈现,但如果它们依赖于 ViewState 或 Postback 事件,则它们将不起作用。

查看验证码控件的代码,这似乎是问题所在。验证被编程为在 LoadPostBackData 期间发生。不幸的是,ASP.Net MVC 中没有回发的概念......因此没有回发数据。

It's not really recommended to use ASP.Net server controls for an ASP.Net MVC site. ASP.Net MVC does not execute the page lifecycle like regular ASP.Net does. The server controls may render, but if they rely on ViewState or Postback events, they will not work.

Looking at the code for the Captcha Control, this seems to be the problem. The validation is programmed to occur during LoadPostBackData. Unfortunately, there is no concept of a postback in ASP.Net MVC... and hence no postback data.

柠檬心 2024-08-10 06:07:24

我写了一篇关于 ASP.NET MVC 验证码控件的完整博客文章。也许值得一看,因为它是最新的:

ASP.NET MVC 验证码控件

I've written a complete blog post about an ASP.NET MVC captcha control. Maybe it's worth to have a look at it, since it's very up to date:

ASP.NET MVC Captcha Control

隱形的亼 2024-08-10 06:07:24

更好的选择是简单地使用 NuGet 包库中的 reCaptchaMvcExtensions。这是一个易于安装和使用的软件包,使用完整的 google reCaptcha。

A better choice is to simply use the reCaptchaMvcExtensions from the NuGet package library. This is a simple to install and use package that uses the full google reCaptcha.

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