Skip to main content
Updated answer to add patch file to update setting value.
Source Link
Sumit Helaiya
  • 3.2k
  • 2
  • 12
  • 23

You can try customizing MediaProvider and GetMediaUrl to get the URL without hash while accessing media in preview mode.

  1. Create a custom MediaProvider
public class MediaProvider : Sitecore.Resources.Media.MediaProvider
    {
        public override string GetMediaUrl(MediaItem item, MediaUrlBuilderOptions options)
        {
            Assert.ArgumentNotNull(item, "item");

            bool isPreviewMode = Sitecore.Context.PageMode.IsPreview;

            var url = base.GetMediaUrl(item, options);

            if (isPreviewMode)
            {
                return url;
            }

            return HashingUtils.ProtectAssetUrl(url);
        }
    }
  1. Update the config change using the patch.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <mediaLibrary>
      <mediaProvider patch:instead="mediaProvider[@type='Sitecore.Resources.Media.MediaProvider, Sitecore.Kernel']"
                     type="YourProjectNameSpace.MediaProvider, YourProjectNameSpace" />
  </mediaLibrary>
  </sitecore>
</configuration>

Another way is to disable for the specific core role by setting Media.RequestProtection.Enabled to false.

Patch the file to update the setting value.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <settings>
     <setting name="Media.RequestProtection.Enabled" value="false" />
    </settings>
  </sitecore>
</configuration>

Hope it helps!

You can try customizing MediaProvider and GetMediaUrl to get the URL without hash while accessing media in preview mode.

  1. Create a custom MediaProvider
public class MediaProvider : Sitecore.Resources.Media.MediaProvider
    {
        public override string GetMediaUrl(MediaItem item, MediaUrlBuilderOptions options)
        {
            Assert.ArgumentNotNull(item, "item");

            bool isPreviewMode = Sitecore.Context.PageMode.IsPreview;

            var url = base.GetMediaUrl(item, options);

            if (isPreviewMode)
            {
                return url;
            }

            return HashingUtils.ProtectAssetUrl(url);
        }
    }
  1. Update the config change using the patch.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <mediaLibrary>
      <mediaProvider patch:instead="mediaProvider[@type='Sitecore.Resources.Media.MediaProvider, Sitecore.Kernel']"
                     type="YourProjectNameSpace.MediaProvider, YourProjectNameSpace" />
  </mediaLibrary>
  </sitecore>
</configuration>

Another way is to disable for the specific core role by setting Media.RequestProtection.Enabled to false.

Hope it helps!

You can try customizing MediaProvider and GetMediaUrl to get the URL without hash while accessing media in preview mode.

  1. Create a custom MediaProvider
public class MediaProvider : Sitecore.Resources.Media.MediaProvider
    {
        public override string GetMediaUrl(MediaItem item, MediaUrlBuilderOptions options)
        {
            Assert.ArgumentNotNull(item, "item");

            bool isPreviewMode = Sitecore.Context.PageMode.IsPreview;

            var url = base.GetMediaUrl(item, options);

            if (isPreviewMode)
            {
                return url;
            }

            return HashingUtils.ProtectAssetUrl(url);
        }
    }
  1. Update the config change using the patch.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <mediaLibrary>
      <mediaProvider patch:instead="mediaProvider[@type='Sitecore.Resources.Media.MediaProvider, Sitecore.Kernel']"
                     type="YourProjectNameSpace.MediaProvider, YourProjectNameSpace" />
  </mediaLibrary>
  </sitecore>
</configuration>

Another way is to disable for the specific core role by setting Media.RequestProtection.Enabled to false.

Patch the file to update the setting value.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <settings>
     <setting name="Media.RequestProtection.Enabled" value="false" />
    </settings>
  </sitecore>
</configuration>

Hope it helps!

Source Link
Sumit Helaiya
  • 3.2k
  • 2
  • 12
  • 23

You can try customizing MediaProvider and GetMediaUrl to get the URL without hash while accessing media in preview mode.

  1. Create a custom MediaProvider
public class MediaProvider : Sitecore.Resources.Media.MediaProvider
    {
        public override string GetMediaUrl(MediaItem item, MediaUrlBuilderOptions options)
        {
            Assert.ArgumentNotNull(item, "item");

            bool isPreviewMode = Sitecore.Context.PageMode.IsPreview;

            var url = base.GetMediaUrl(item, options);

            if (isPreviewMode)
            {
                return url;
            }

            return HashingUtils.ProtectAssetUrl(url);
        }
    }
  1. Update the config change using the patch.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <mediaLibrary>
      <mediaProvider patch:instead="mediaProvider[@type='Sitecore.Resources.Media.MediaProvider, Sitecore.Kernel']"
                     type="YourProjectNameSpace.MediaProvider, YourProjectNameSpace" />
  </mediaLibrary>
  </sitecore>
</configuration>

Another way is to disable for the specific core role by setting Media.RequestProtection.Enabled to false.

Hope it helps!