【发布时间】:2014-05-30 00:16:29
【问题描述】:
我正在使用 Razor 做一个单一的概念验证 cshtml 页面,没有控制器。我使用 ASP.NET 4.5。
此页面有一个表单。它的动作也指向这个页面。因此,当表单提交时,它会转到同一页面。
表单有一个名为“描述”的字段。它是必填字段,但允许用户输入 html sn-ps。
我有以下检查用户输入:
Validation.RequireField("description", "Description is required.");
但是,当用户在“描述”字段中输入 html sn-ps 并提交表单时,网站会显示以下错误消息:
A potentially dangerous Request.Form value was detected from the client (Description="<p>This bilingual.....
....
Line 43: description = Request.Form["description"];
.....
此页面处于非常安全的环境中,因此允许使用 html sn-ps。
让我们把最佳做法放在一边。如何使描述字段成为必填项并同时允许 html sn-ps?我的表单中有多个字段允许使用 html sn-ps。
希望能找到不碰web.config的解决方案。
问候和感谢。
【问题讨论】:
标签: c# validation razor