Obtain friendly URL of page

Vote:
 

Hello,

I have a PageReference property and I want o obtain the URL to that page. I'm using EpiServer 9.

Initially I was using: EPiServer.Web.Routing.UrlResolver.Current.GetUrl(myPageReference); but this method can return the url in this format “/EPiServer/CMS/Content/mypage,,74/?epieditmode=True”  instead on "/myPage" (when we are in edit mode).

I saw some suggestions to use this: EPiServer.Web.Routing.UrlResolver.Current.GetUrl(myPageReference, null, new EPiServer.Web.Routing.VirtualPathArguments() { ContextMode = EPiServer.Web.ContextMode.Default });, which seems that is working to obtain the frienly URL.

Is this the proper/best way to do it, or is there another method in this Epi version?

Thanks,

Bogdan

#149405
May 31, 2016 14:59
Vote:
 

I've been using this code the get external URL:

public string GetExternalUrl(PageReference pageReference)
{
    var internalUrl = UrlResolver.Current.GetUrl(pageReference);
    var url = new UrlBuilder(internalUrl);
    Global.UrlRewriteProvider.ConvertToExternal(url, null, Encoding.UTF8);

    string externalUrl = HttpContext.Current == null
        ? UriSupport.AbsoluteUrlBySettings(url.ToString())
        : HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + url;

    return externalUrl;
}
#149407
May 31, 2016 15:08
Vote:
 

I was hoping that Episerver 9 would have a method for getting the URL

#149446
Jun 01, 2016 9:35
Vote:
 

I'm going to keep posting my blog post until Episerver implements this functionality in UrlResolver. Please see http://dodavinkeln.se/post/how-to-get-the-external-url-to-content.

#149489
Jun 01, 2016 17:41
Vote:
 

Thanks Johan, so I should understand that EPi doesn't have anything implemented this functionality and we still need to use a custom method for this.

#149510
Jun 02, 2016 10:27
Vote:
 

It depends on what you mean. The functions used in my code are built-in.

#149511
Jun 02, 2016 10:35
Vote:
 

The only "hacky" part in my code is to obtain the absolute URL. So if you only want the friendly URL (which might be relative) you can remove the last part in the code. You can also set default values on the language parameter.

#149514
Jun 02, 2016 11:22
* 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.