【发布时间】:2011-08-06 15:10:24
【问题描述】:
我明白为什么会发生这种情况,但我需要解决方法。我在 StackOverflow 上查看了其他一些问题,但没有一个有帮助。我不想禁用整个网站的输入验证,因为这绝对是危险的。我只有一个(至少现在)需要禁用输入验证的地方。
我使用 [ValidateInput(false)] 属性修饰了 Action Method,并且使用 Html.Encode 对字符串进行了编码。但是,我仍然遇到同样的错误。这是我的看法:
<div id="sharwe-categories">
<ul class="menu menu-vertical menu-accordion">
@foreach(var topLevel in Model)
{
var topLevelName = Html.Encode(topLevel.Name);
<li class="topLevel">
<h3>
@Html.ActionLink(topLevel.Name, "Index", "Item", new { category = topLevelName }, new {@class = "main"} )
<a href="#" class="drop-down"></a>
</h3>
<ul>
@foreach (var childCategory in topLevel.Children)
{
var childcategoryName = Html.Encode(childCategory.Name);
<li>@Html.ActionLink(childCategory.Name, "Index", "Item", new RouteValueDictionary { { "category", topLevelName }, { "subcategory", childcategoryName } }, null)</li>
}
</ul>
</li>
}
</ul>
</div>
如您所见,没有用户输入。但是有些类别名称中有一些“危险”字符...有什么解决办法吗?
【问题讨论】:
-
你能提供导致问题的值吗?
-
@Robert Koritnik:包含“&”或“,”或任何危险字符的值...
标签: security validation asp.net-mvc-3 razor