Html Helper extension for Canonical Link does not include the hostname.


In the EPiServer.Web.Mvc.Html.CanonicalLink function, the returned value does not include the Hostname, which is required for Canonical Links. Thanks!

Apr 30, 2021 16:47

Hi John! I recently needed to add canonical links including the hostname as well. I ended up adding an extension method to UrlHelper to handle this:

        public static string CanonicalUrl(this UrlHelper urlHelper, PageData page)
            var resolver = ServiceLocator.Current.GetInstance<UrlResolver>();
            var contentUrl = resolver.GetUrl(page.ContentLink, page.Language.TwoLetterISOLanguageName, new VirtualPathArguments {
                ContextMode = ContextMode.Default,
                ForceAbsolute = true,
                ForceCanonical = true,

            return contentUrl;


Apr 30, 2021 18:30

There might be more things to check when generating canonical urls. I haven't used that extension for a while (might be obsolete)..

May 24, 2021 21: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.