gpt4 book ai didi

asp.net-core - BotDetect 和 ASPNET Razor 页面未验证

转载 作者:行者123 更新时间:2023-12-04 13:24:51 27 4
gpt4 key购买 nike

我决定在我的项目中使用 BotDetect Captcha 来阻止垃圾邮件,但是,由于 Razor Pages 不支持过滤器,我无法检查用户是否输入了正确的验证码。
在他们的网站上,他们说使用这个属性来检查验证码是否有效[CaptchaValidationActionFilter("CaptchaCode", "ExampleCaptcha", "Wrong Captcha!")]但是,razor 页面不允许在页面方法上使用属性。
深入研究属性的源代码,我发现了这个

MvcCaptcha mvcCaptcha = new MvcCaptcha(this.CaptchaId);
if (mvcCaptcha.IsSolved) { }
但是,当我直接在 OnPost 中尝试该代码时方法, mvcCaptch.IsSolved总是返回假。
检查 session 变量还会显示所有 BDC_此控件工作所需的值,所以我在这里碰壁了。希望有人可以帮助我。谢谢。
官方文档,如果有帮助的话,虽然,我在网站 https://captcha.com/mvc/mvc-captcha.html 上找不到任何对 Razor Pages 的引用。

最佳答案

我发现有一个属性 CaptchaModelStateValidation您可以将属性应用于绑定(bind)到验证码输入的 Razor 页面模型属性。这样您就可以在 ModelState 中自动获得验证.
这是验证验证码的示例模型。

public class CaptchaValidatorModel : PageModel
{
public void OnPost()
{
if (ModelState.IsValid)
{
// Perform actions on valid captcha.
}
}

[BindProperty]
[Required] // You need this so it is not valid if the user does not input anything
[CaptchaModelStateValidation("ExampleCaptcha")]
public string CaptchaCode { get; set; }
}
该页面使用文档示例中提供的代码。
@page
@model CaptchaWebApplication.Pages.CaptchaValidatorModel
@{
ViewData["Title"] = "Captcha";
}
<form method="post">
<label asp-for="CaptchaCode">Retype the code from the picture:</label>
<captcha id="ExampleCaptcha" user-input-id="CaptchaCode" />
<div class="actions">
<input asp-for="CaptchaCode" />
<input type="submit" value="Validate" />
<span asp-validation-for="CaptchaCode"></span>
@if ((HttpContext.Request.Method == "POST") && ViewData.ModelState.IsValid)
{
<span class="correct">Correct!</span>
}
</div>
</form>

关于asp.net-core - BotDetect 和 ASPNET Razor 页面未验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69151097/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com