我在网站上有一个联系表单,发现一段时间以来,我一直收到错误消息:“从客户端检测到潜在的Request.Form值危险。”>
我已经采取了一些措施来阻止这些行为,包括:
型号:
[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"); }
然而,到目前为止,这些方法仍无法成功阻止出现这些错误消息。
该错误从未声明已发布的整个消息,所以我看不到是什么触发了它。我还可以添加其他内容来阻止这些内容通过,还是可以查看表单中发布的内容?
谢谢
我的网站上有一个联系表单,有一段时间以来,我一直在收到“从客户端检测到潜在危险的Request.Form值”错误。我已经采取了一些措施来尝试...
我认为您遇到的问题是应用程序在检查正则表达式之前拒绝了该值。