gpt4 book ai didi

c# - MVC Url 请求 - 路径中的非法字符

转载 作者:太空宇宙 更新时间:2023-11-03 15:35:54 25 4
gpt4 key购买 nike

概述:

  • 404 错误页面已在 web.config 中配置并正常运行
  • 使用 Umbraco v6.2
  • 自定义错误设置为 RemoteOnly

问题是当我在 URL 中放入“%7C”时,我收到了:

Illegal characters in path.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Illegal characters in path.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentException: Illegal characters in path.]
System.IO.Path.GetExtension(String path) +14365864
Umbraco.Core.UriExtensions.IsClientSideRequest(Uri url) +23
Umbraco.Web.UmbracoModule.BeginRequest(HttpContextBase httpContext) +365
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165

%7C 是管道“|”。 %7C 是唯一给我 YSOD 的(我试过的)。

如果我输入任何东西(我已经尝试了 30 多种组合),例如 %7A、%2A,那么有时它会给我这个错误,而不会转到 404 页面,但永远不会出现 YSOD:

Bad Request - Invalid URL

HTTP Error 400. The request URL is invalid.

web.config

<customErrors mode="RemoteOnly" defaultRedirect="~/error-page" />

<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="503" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="~/error-page" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="~/error-page" responseMode="ExecuteURL" />
<error statusCode="503" prefixLanguageFilePath="" path="~/error-page" responseMode="ExecuteURL" />
</httpErrors>

在 Umbraco 中,有一个配置文件 (umbracoSettings.config),其中包含一个包含字符替换的 XML 部分。

例子:

 <char org="~"></char>
<char org=" ">-</char>
<char org="&quot;"></char>
<char org="'"></char>
<char org="%"></char>
<char org="."></char>
<char org="|"></char>

你可以看到管道在里面。如果我输入 URL,

local.website.com/asdf| (注意管道),它被编码为 local.website.com/asdf%7C .

我尝试添加 <char org="%7C"></char>但它不起作用。我错过了什么吗?这是已知错误吗?

最佳答案

这实际上不是错误或 Umbraco 相关问题,而是 ASP.NET 验证 HTTP 请求中的 URL 是否需要是有效的 Windows 文件路径的方式。

你可以通过使用来绕过它

<httpRuntime relaxedUrlToFileSystemMapping="true" />

根据 documentation :

The RelaxedUrlToFileSystemMapping property determines how the URL in an incoming HTTP request will be validated. If this property is false, the URL is validated by using the same rules that determine whether a Windows file system path is valid.

关于c# - MVC Url 请求 - 路径中的非法字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31881877/

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