gpt4 book ai didi

当 URL 中存在冒号时,Azure 网站会抛出 500 错误

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

外部客户端正在使用包含冒号 (:) 字符的 URL 访问我的 Azure 网站。该请求无效,但在我的旧 IIS 服务器上它会给出 404 错误。在 Azure 上,相同的 URL 将给出 500 错误。这浪费了我的时间,因为我必须检查日志。这是请求的示例:

http://www.example.com/http:/www.example.com

有没有办法在服务器端避免这种行为,并给出 4xx 错误?请记住,此问题仅出现在 Azure 上,我无法控制请求。

最佳答案

如果您正在运行 .NET 应用程序,则这是由 ASP.NET HTTP 运行时引起的,更具体地说是由其请求过滤功能引起的。

如果 URL 路径包含任何不允许的字符 ( <,>,*,%,&,:,\\,? ),运行时将引发异常,并且由于该异常,IIS 将返回错误代码 500。

System.Web.HttpException: A potentially dangerous Request.Path value was detected from the client (:).

您可以configure web.config 中不允许使用的字 rune 件。

<system.web>
<httpRuntime targetFramework="4.5" requestPathInvalidCharacters="*,%" />
</system.web>

但我会小心,因为这种更改可能会产生一些安全隐患。

关于当 URL 中存在冒号时,Azure 网站会抛出 500 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34197132/

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