URL of Assets when accessing Preview Mode

Vote:
 

When accessing a preview of a page via Edit mode the url of assets is given like

/EPiServer/CMS/Content/globalassets/project-detail-01.jpg,,23?epieditmode=False

When using Model.ImageUrl

I am doing a HttpWebRequest on this string for the file although as the request is done anonymously their is no permission to access it.


How can I overcome this, when accessing the page directly the URL returned is fine i.e. globalassets/project-detail-01.jpg

I'd rather not start trimming string if their is a better way


Minesh

#91174
Sep 29, 2014 10:26
Vote:
 

Hi!

Normally, when requesting an URL in the system, you will get the URL for the current "mode" that you are in. The three modes are:

  • Default (public URL).
  • Edit.
  • Preview.

There are several reasons for this. The reason that we have a different URL (and behind the scenes also a different route and handler) is that we don't want to have images cached in the UI. This is because we want editors to be able to change and image and have that reflected directly in the UI (instead of having the image cached in the browser).

If you want to have a specific URL for a content item and specific mode, you can call the URL resolver directly and specify the mode you want to have, for instance:

var mode = ContextMode.Preview;
url = UrlResolver.Current.GetUrl(content.ContentLink, content.LanguageBranch(), new VirtualPathArguments() { ContextMode = mode });

#91189
Sep 29, 2014 12:51
Vote:
 

Thank you

#91233
Sep 30, 2014 15:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.