我的网站上有一个联系表格,一段时间以来我一直收到“从客户端检测到潜在危险的 Request.Form 值”的错误。
我已经采取了一些措施来试图阻止这些,包括:
- 添加防伪令牌
- 将正则表达式添加到联系表单模型以防止发布大多数特殊字符
- 将 Recapcha V3 添加到表单中
模型:
[Required]
[DataType(DataType.MultilineText)]
[RegularExpression(@"^[a-zA-Z0-9!?£$'"",.&\-\s]+$", ErrorMessage = "Special characters are not allowed")]
public string Message { get; set; }
看法
@using (Html.BeginForm(null, null, FormMethod.Post, new { controller = "home", action = "Contact"}))
{
@Html.AntiForgeryToken()
<div class="form">
<div class="form_inner">
<div class="fieldset">
@Html.TextAreaFor(model => model.Message, 8, 25, new { required = "required" })
@Html.ValidationMessageFor(model => model.Message)
</div>
<footer>
@Html.HiddenFor(model => model.GoogleCaptchaToken)
<input type="submit" value="Send Email" class="btn btn_submit" />
</footer>
</div>
</div>
}
控制器
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Contact(Contact model)
{
if (ModelState.IsValid)
{
var isCaptchaValid = await IsCaptchaValid(model.GoogleCaptchaToken);
if (isCaptchaValid)
{
_contactUsService.SendEmail(model);
}
else
{
ModelState.AddModelError("GoogleCaptcha", "The captcha is not valid");
} }
return Redirect("/contact/thankyou");
}
然而,到目前为止,这些还没有成功阻止这些错误消息通过。
该错误从未说明已发布的整个消息,因此我看不到触发它的原因。我可以添加更多内容来防止这些通过,或者我可以看到从表格中发布的内容吗?
谢谢