ExternalLinkUrl() is not present in 7.5

Vote:
 

I am upgrading a site from EpiServer 7 to 7.5 and got an error as below:

‘Project.Models.Pages.ArticlePage' does not contain a definition for 'ExternalLinkUrl' and no extension method 'ExternalLinkUrl' accepting a first argument of type ‘Project.Models.Pages.ArticlePage' could be found (are you missing a using directive or an assembly reference?)

Infact after some investigation I found that the class LinkExtensions in which this method is present itself is not there.

Anyone has any idea what is the good replacement for this?

 

#143273
Jan 19, 2016 6:43
Vote:
 

Hi, Ashoka,

Take a look at this blogpost (make sure to read comments section as well).

BR,

Marija

#143277
Jan 19, 2016 9:53
Vote:
 

There is a Geta.EPi.Extensions library which has extension method for it: GetFriendlyUrl()

It also has multipe other usefult extension methods for EPiServer development.

GitHub repository for it: https://github.com/Geta/EPi.Extensions

EPiServer NuGet feed: http://nuget.episerver.com/en/OtherPages/Package/?packageId=Geta.EPi.Extensions

#143279
Jan 19, 2016 10:34
Vote:
 

Thanks Marija, I tried the solution given by you and now there is no more compilation error.

But I am not able to run the application and verify what it returns as I have one more issue in the migrated code.

Thanks again for your help.

#143283
Jan 19, 2016 14:10
Vote:
 

The solution given in the blog post is not complete though. Not if you have multiple hosts or websited configured in your Episerver instance. There is another parameter you can use in the UrlResolver, ForceCanonical, unfortuantely it doen't give you an external URL but it solves some issues.

We use this code:

public ExternalUrlResolver(ContentReference contentLink, CultureInfo contentLanguage, bool absoluteUrl, string languageBranch)
{
    var result = ServiceLocator.Current.GetInstance<UrlResolver>().GetUrl(
        contentLink,
        languageBranch,
        new VirtualPathArguments
        {
            ContextMode = ContextMode.Default,
            ForceCanonical = absoluteUrl
        });

    // HACK: Temprorary fix until GetUrl and ForceCanonical works as expected,
    // i.e returning an absolute URL even if there is a HTTP context that matches the page's 
    // site definition and host.
    if (absoluteUrl)
    {
        Uri relativeUri;

        if (Uri.TryCreate(result, UriKind.RelativeOrAbsolute, out relativeUri))
        {
            if (!relativeUri.IsAbsoluteUri)
            {
                var siteDefinitionResolver = ServiceLocator.Current.GetInstance<SiteDefinitionResolver>();
                var siteDefinition = siteDefinitionResolver.GetDefinitionForContent(contentLink, true, true);
                var hosts = siteDefinition.GetHosts(contentLanguage, true).ToList();

                var host = hosts.FirstOrDefault(h => h.Type == HostDefinitionType.Primary) 
                    ?? hosts.FirstOrDefault(h => h.Type == HostDefinitionType.Undefined);

                var basetUri = siteDefinition.SiteUrl;

                if (host != null && host.Name.Equals("*") == false)
                {
                    // Try to create a new base URI from the host with the site's URI scheme. Name should be a valid
                    // authority, i.e. have a port number if it differs from the URI scheme's default port number.
                    Uri.TryCreate(siteDefinition.SiteUrl.Scheme + "://" + host.Name, UriKind.Absolute, out basetUri);
                }

                var absoluteUri = new Uri(basetUri, relativeUri);

                this.ExternalUrl = absoluteUri.AbsoluteUri;
                return;
            }
        }
    }

    this.ExternalUrl = result;
}
#143284
Jan 19, 2016 14:23
Vote:
 
#143287
Jan 19, 2016 14:58
* 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.