You can try customizing MediaProvider
and GetMediaUrl
to get the URL without hash
while accessing media in preview mode.
- 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);
}
}
- 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!