Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
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;
}
There might be more things to check when generating canonical urls. I haven't used that extension for a while (might be obsolete)..
In the EPiServer.Web.Mvc.Html.CanonicalLink function, the returned value does not include the Hostname, which is required for Canonical Links. Thanks!