Sitecore is unable to open media/regular items when using encodeNameReplacements


Description

Sitecore may show the Item Not Found page as a result of requests to the media item if the media prefix or the name of the item contains characters included in the encodeNameReplacements configuration section. For example, if this configuration section contains the following node:

<replace mode="on" find=" " replaceWith="-" />

Case 1. Fixed in Sitecore 7.2 rev. 151021 (Update-5).
Using -/media/ as a media prefix will fail with the standard IIS Not Found page.

Case 2. Fixed in Sitecore 8.0 rev. 150427 (Update-3).
A request to the media item with the /Files/Media-Item path results in the Item Not Found page.

Case 3. Fixed in Sitecore 9.0 rev. 171002 (Initial Release).
In an MVC site, a wildcard item is used as a context item when the URL contains the characters from encodeNameReplacements configuration section.
For example, if you have /sitecore/content/Home/* item along with /sitecore/content/Home/MVC Test item and try to open http:///MVC-Test, the context item will be set to /sitecore/content/Home/*.

Case 4. Fixed in Sitecore 8.1 rev. 160302 (Update-2)
A request to an item that has both encoded and non-encoded symbols in its path will result in the Item Not Found page.
For example, Home/Sample Item-Name or Home/Sample Item/Item-Name

Solution

Case 1 and Case 2:
1. Place the attached Sitecore.Support.414259.416567.dll file in your \bin folder.
2. In the web.config file, replace the following line:

<requestParser type="Sitecore.Resources.Media.MediaRequest, Sitecore.Kernel" />
with
<requestParser type="Sitecore.Support.Resources.Media.MediaRequest, Sitecore.Support.414259.416567" />
3. In the web.config file, also replace the following line:
<processor type="Sitecore.Pipelines.HttpRequest.CustomHandlers, Sitecore.Kernel" />
with
<processor type="Sitecore.Support.Pipelines.HttpRequest.CustomHandlers, Sitecore.Support.414259.416567" />

Case 3:
1. Open the \App_Config\Include\Sitecore.Mvc.config file.
2. Change the order of the defined processors in the <mvc.getPageItem> section as follows:

<mvc.getPageItem>
 <processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.SetLanguage, Sitecore.Mvc"/>
 <processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromOldContext, Sitecore.Mvc"/>
 <processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromRouteValue, Sitecore.Mvc"/>
 <processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromRouteUrl, Sitecore.Mvc"/>
</mvc.getPageItem>

Case 4:
Rename all the items so that their path name either contains only encoded symbols (spaces) or only non-encoded symbols (dashes). For example, Home/Sample Item Name or Home/Sample-Item/Item-Name.
Alternatley, you can change the ItemNameValidation setting in the \web.config or \App_Config\Sitecore.config files to ^[\w\*\$]([\w\-\$]*|[\w\s\$]*)(\(\d{1,}\)){0,1}$ in order to prevent users from creating the items that have both spaces and the - characters in their names.

Notes

Starting from Sitecore 8.1 rev. 160302 (update-2), additional settings have been introduced that allow you to use both encoded and non-encoded characters in a path or name.

 <setting name="ItemNameAllowMixingReplacementCharacters" value="true" />
 <setting name="ItemResolving.FindBestMatch" value="DeepScan" />

More detailed information about the impact of these settings can be found in the Sitecore.config file.