gpt4 book ai didi

asp.net-mvc - 获取 "A potentially dangerous Request.Path value was detected from the client (&)"

转载 作者:行者123 更新时间:2023-12-03 04:39:53 29 4
gpt4 key购买 nike

我遇到了一个遗留代码问题,要求我支持随机 URL,就像它们是对主页的请求一样。某些 URL 中包含会生成错误“从客户端检测到潜在危险的 Request.Path 值 (&)” 的字符。该网站是用 ASP.Net MVC 3(C# 语言)编写的,并在 IIS 7.5 上运行。

这是一个示例 URL...

http://mywebsite.example/Test123/This_&_That

以下是我的捕获所有路由设置的方法(我有其他路由来捕获特定页面)...

routes.MapRoute(
"Default", // Route name
"{garb1}/{garb2}", // URL with parameters
new { controller = "Website", action = "Home", garb1 = UrlParameter.Optional, garb2 = UrlParameter.Optional } // Parameter defaults
);

我已将以下内容添加到我的 web.config 文件中...

<configuration>
<system.web>
<pages validateRequest="false" />
<httpRuntime requestValidationMode="2.0" />
</system.web>
<configuration>

我还向应该捕获 url 的操作添加了 ValidateInput 属性...

public class WebsiteController : Controller
{
[ValidateInput(false)]
public ActionResult Home()
{
return View();
}
}

但我仍然收到错误。有什么想法吗?我错过了什么?现在我只是在本地开发服务器上运行(我还没有在生产中尝试过这些修复)。

最佳答案

虽然您可以在配置文件中尝试这些设置

<system.web>
<httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0" />
<pages validateRequest="false" />
</system.web>

我会避免在 URL 路径中使用“&”等字符,而是用下划线替换它们。

关于asp.net-mvc - 获取 "A potentially dangerous Request.Path value was detected from the client (&)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6025522/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com