问题
Overview:
- 404 error page is configured in web.config and working
- Using Umbraco v6.2
- customErrors are set to
RemoteOnly
The issue is when I put "%7C" in the URL, I receive this:
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 is a pipe "|". %7C is the only one (that I've tried) that gives me the YSOD.
If I put anything (I've tried 30+ combinations), such as %7A, %2A, then sometimes it'll give me this error w/o going to the 404 page, but never the 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>
In Umbraco, there is a config file (umbracoSettings.config) that has an XML section that houses character replacement.
Example:
<char org="~"></char>
<char org=" ">-</char>
<char org="""></char>
<char org="'"></char>
<char org="%"></char>
<char org="."></char>
<char org="|"></char>
You can see that the pipe is in there. If I put into the URL,
local.website.com/asdf|
(notice the pipe), it gets encoded into local.website.com/asdf%7C
.
I have tried to add <char org="%7C"></char>
but it doesn't work. Am I missing something? Is this a known bug?
回答1:
This is not actually a bug or Umbraco related issue, it is how ASP.NET validates that the URL in an HTTP request is required to be a valid Windows file path.
You can get around of it by using
<httpRuntime relaxedUrlToFileSystemMapping="true" />
As per 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.
回答2:
Had to add to web.config
<remove statusCode="400" subStatusCode="-1" />
<error statusCode="400" prefixLanguageFilePath="" path="~/error-page" responseMode="ExecuteURL" />
Also once I turned errors on customErrors="On"
this error went away.
If anybody has a better alternative or reasoning behind this, I'm open for suggestions
来源:https://stackoverflow.com/questions/31881877/mvc-url-request-illegal-characters-in-path