I have two languages on my site: en and de.
When I'm trying to open http://{HOSTNAME}/%20/
- I'm recieving error:
Question: How can I fix this issue and process this request in correct way?
As much as I hate to put this as an answer, but this is not a Sitecore issue.
this doesn't fail: http://sitecoredemo/sitecore/service/notfound.aspx/%20/
neither does http://sitecoredemo/sitecore/service/notfound/%20/
neither does http://sitecoredemo/sitecore/%20/
I have tested this on IIS 7, IIS8, and IIS10. On Sitecore sites and non-Sitecore sites. All behave the same way.
From looking at Google, there are other people having this issue: https://stackoverflow.com/questions/26364213/asp-net-url-ending-in-20-is-not-getting-to-application-code https://our.umbraco.org/forum/using-umbraco-and-getting-started/79164-whitespace-in-url-causes-server-error
I suspect that this is either an IIS or URL Rewrite Bug... or an undocumented "feature" that serves a purpose.
Additionally, /%20/
is not just the trigger. I have tried numerous other encoded characters and all react the same way. There is something in IIS with respect to the unencoding of the URL that breaks the web.config configuration when serving the page.
On a side note.. if anyone wanted to clog up log files, this would be a fantastic way to do it.
Honestly, aside from crazy QA test cases purposefully doing it... There shouldn't be anything happening that is redirecting a user to this type of URL unless you have an error in your URL Rewrite rules or bad redirect rules in your web application.
One search result netted a comment to add the following to the web.config, but this appears to also open up security issues.
<httpRuntime relaxedUrlToFileSystemMapping="true" />
Since the issue is with IIS, additional error page handling needs to be set up in the web.config.
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="400" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/error" responseMode="ExecuteURL" />
<error statusCode="400" prefixLanguageFilePath="" path="/error" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/error" responseMode="ExecuteURL" />
</httpErrors>
This at least allows a proper error page to render, and not the default Yellow Screen of Death. (Thanks @jammykam for the comment)
You can use URL Rewrite module for your issue :
1) Open the Internet Information Services(IIS) Manager
2) Select “Your Web Site”
3) In the Feature View click “URL Rewrite“
4) In the “Manage Providers” pane on right hand side click on “View Rewrite Maps…” and then select "Add Rewrite Map.."
5)Set the map name, SpaceMap for example
6) In the “Actions” pane on right hand side click on “Add Mapping Entry…”
In the "Original value" field insert / /, in the “New Value“ set /404page and Click "Ok"
7) In the “Actions” pane click on “Add rule(s)…” and then select "Rule with rewrite Map" template
8) Leave “Rewrite” in the rule action and select the SpaceMap in the "rewrite map" field and click "Ok"
9) Enter your url : http://hostname/ / and it will redirect to the pagefrom step 6
This really an IIS issue. The solution is to update the httpErrors under the system.webServer like below:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="400" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/error" responseMode="ExecuteURL" />
<error statusCode="400" prefixLanguageFilePath="" path="/error" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/error" responseMode="ExecuteURL" />
</httpErrors>
%20
is just an URL encodedSpace
character. What do you expect to happen? Do you have an item that has aSpace
as title?%20
as a virtual directory and inherits the Web.config from the "root site". Weird.