当我没有使用 razor Html 助手时,为什么我的输入没有得到验证?
Why does my input not get validated when I'm not utilizing razor Html helpers?
假设我有一个不使用 razor html helpers/a 模型的简单 Web 表单。
<form id="survey-form" action="@Url.Action("Submit", "Questionnaire")" method="post">
<textarea name="1" form="survey-form">
</form>
以上表格使用
提交
$("#survey-form").submit();
在控制器上发布到以下测试方法
[HttpPost]
[ValidateAntiForgeryToken]
[ValidateInput(true)]
public ActionResult Submit()
{
NameValueCollection nvc = Request.Form;
return View();
}
<script>alert("xss!")</script>
到我的文本输入没有得到控制器的验证。我通常希望抛出 "A potentially dangerous Request.Form was detected from the client ..."
异常的地方。
该方法不会 return 任何异常或消息,并且允许 运行。
MSDN 文档说
The HttpRequest class uses input validation flags to track whether to perform validation on the request collections accessed through the Cookies, Form, and QueryString properties.
由于我正在发布和处理具有潜在危险值的已发布表单,因此我希望我的输入得到验证。
我是否可以在不使用 ASP.NET MVC 约定的情况下仍然使用简单的 MVC 助手(如 ValidateInput 属性)来验证用户输入? (例如,使用 razor html 助手和模型等创建表单)
编辑:
由于实际到达控制器上的 Action 的值似乎有些混乱,这里是一个屏幕截图,显示值确实到达了函数。
我认为您应该包括 FormCollection
作为 Submit
ActionResult 的参数。
假设我有一个不使用 razor html helpers/a 模型的简单 Web 表单。
<form id="survey-form" action="@Url.Action("Submit", "Questionnaire")" method="post">
<textarea name="1" form="survey-form">
</form>
以上表格使用
提交$("#survey-form").submit();
在控制器上发布到以下测试方法
[HttpPost]
[ValidateAntiForgeryToken]
[ValidateInput(true)]
public ActionResult Submit()
{
NameValueCollection nvc = Request.Form;
return View();
}
<script>alert("xss!")</script>
到我的文本输入没有得到控制器的验证。我通常希望抛出 "A potentially dangerous Request.Form was detected from the client ..."
异常的地方。
该方法不会 return 任何异常或消息,并且允许 运行。
MSDN 文档说
The HttpRequest class uses input validation flags to track whether to perform validation on the request collections accessed through the Cookies, Form, and QueryString properties.
由于我正在发布和处理具有潜在危险值的已发布表单,因此我希望我的输入得到验证。
我是否可以在不使用 ASP.NET MVC 约定的情况下仍然使用简单的 MVC 助手(如 ValidateInput 属性)来验证用户输入? (例如,使用 razor html 助手和模型等创建表单)
编辑:
由于实际到达控制器上的 Action 的值似乎有些混乱,这里是一个屏幕截图,显示值确实到达了函数。
我认为您应该包括 FormCollection
作为 Submit
ActionResult 的参数。