我在ASP NET 4中遇到以下错误:
A potentially dangerous Request.Path value was detected from the client (<).我读到我需要在我的Web.config中使用requestValidationMode="2.0“:
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime requestValidationMode="2.0" />
</system.web>所以我的方法看起来像这样:
[ValidateInput(false)]
public ActionResult Search(string query, string type){
//method body
return result;
}它工作得很好。但是,我不能修改我的Web.config文件,因为许多其他应用程序依赖于此文件,它可能会导致安全漏洞或其他地方的错误。
我的应用程序足够安全,可以接受特殊字符,但我不能对正在开发的系统的其余部分说同样的话。在我的方法中有接受特殊字符作为输入的替代方法吗?
示例:
www.mydomain.com/search/query/<myquery<ffoo/type/dept发布于 2012-11-30 08:15:27
我在我当前的项目中也有同样的问题..我将发布我必须添加的内容,以便纠正这个问题..还请记住,在IIS4.0中有一个错误,在IIS2.0中使用它我的项目是3.5,但是我认为.NET AppPool他们让我们的项目运行4.0
我在我的web配置文件中添加了这个,它纠正了我遇到的一些奇怪的错误
<httpRuntime requestValidationMode="2.0"
requestPathInvalidCharacters="*,:,&,\"
relaxedUrlToFileSystemMapping="true"
/>对于MVC,您可以尝试执行以下操作
using System.Web.Helpers;
[HttpPost]
[ValidateInput(false)]
public ViewResult Edit(ContentTemplateView contentTemplateView)
{
FormCollection collection = new FormCollection(Request.Unvalidated().Form);https://stackoverflow.com/questions/13637035
复制相似问题