2012-11-30 34 views
3

我在ASP NET 4得到以下错误:有潜在危险的请求在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 
+0

可能复制http://stackoverflow.com/questions/4361907/asp-net-mvc-3-validaterequestfalse-not-working-with-formcollection – Kath

回答

1

我在当前project..I同样的问题会发布什么,我不得不为了纠正这种添加..也请记住,有一个错误.NET 4.0在哪里使用.Net 2.0工作我的项目是3.5但是我认为IIS AppPool他们有我们的项目运行4.0

我在我的网络配置文件中添加了这个,它纠正了奇怪的错误,我是体验

<httpRuntime requestValidationMode="2.0" 
    requestPathInvalidCharacters="*,:,&amp;,\" 
    relaxedUrlToFileSystemMapping="true" 
/> 

为MVC,你可以试试下面的

using System.Web.Helpers; 

[HttpPost] 
[ValidateInput(false)] 
public ViewResult Edit(ContentTemplateView contentTemplateView) 
{ 
    FormCollection collection = new FormCollection(Request.Unvalidated().Form);