Try our conversational search powered by Generative AI!

Can you get the "public" URL of a page when rendering in Edit Mode?


Whenin Edit Mode, every attempt to get the URL for a page returns the Edit Mode URL.  I get why (you want people to continue navigating in Edit Mode), but I have a need to get the "public" URL while in Edit Mode.


Jan 15, 2014 16:25

Use UrlResolver and its GetUrl(ContentReference contentLink, string language, VirtualPathArguments virtualPathArguments) method. Set the ContextMode property for virtualPathArguments to Default.

Jan 15, 2014 17:03

For instance:

urlResolver.Current.GetUrl(content.ContentLink, content.LanguageBranch(), new VirtualPathArguments() { ContextMode = ContextMode.Default});

Jan 15, 2014 17:05

Is this possible in CMS 7 (not 7.5)?

Jan 15, 2014 18:15

This method is available in 7.5 only. I'm actually not sure of if and how it can be done in EPiServer 7.

Jan 16, 2014 7:54

We are using this extension method in 7.1

public static string FriendlyLinkURL(this PageData pageData)
            var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();
            var url = urlResolver.GetVirtualPath(pageData.ContentLink);
            return !string.IsNullOrWhiteSpace(url) ? url.ToLowerInvariant() : string.Empty;


Jan 16, 2014 7:55

Henrik -- that works, but in Edit Mode it still returns the Edit Mode URL, not the "public" URL.  This is my core problem.

Jan 16, 2014 15:31

Interesting, should take a look at that, then we have wrong addresses in edit mode as well

Jan 17, 2014 15:02
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.