Performance degradation when the media link prefix contains tilde


Description

Using the default media link prefix ("~/media") that contains a tilde character (~) may lead to the performance degradation when the Sitecore website is experiencing high load.

The issue may be caused by the tilde character in the URL that may cause unnecessary delays at the Windows Kernel level in the time it takes to process the web request.

More specifically, before such a request reaches Sitecore application, it is processed by IIS which performs ACL check on the file system. If the path in the URL contains the tilde, these ACL checks are more expensive that usual ones and may become a performance bottleneck for the server.

Solution

Change the media prefix to use dash instead of tilde to optimize performance:

  1. Set the value of the Media.MediaLinkPrefix setting in the web.config to the alternative prefix:
  2. <setting name="Media.MediaLinkPrefix" value="-/media" />
  3. Add the following line to the customHandlers section (make sure NOT to remove the existing one that is mapped to "~/media"):
  4. <customHandlers>
       <handler trigger="-/media/" handler="sitecore_media.ashx" />
       <handler trigger="~/media/" handler="sitecore_media.ashx" />
       …
    </customHandlers>