I'm currently developing a site where I'm using custom routes and virtual content, the virtual content model inherits from PublishedContentModel in which I override the URL property to give my custom route rather than the wrapped contents URL. However when setting the canonical URL meta tag I use the UrlWithDomain() extension but this doesn't seem to use the overridden URL property to base it off. Is this by design or a bug? If by design is there some other method I can use to get this to work by any chance?
UrlWithDomain is an extension method of IPublishedContent rather than PublishedContentModel, so will use the original absolute URl instead of your modified one.
UrlWithDomain ultimately does this:
return UmbracoContext.Current.UrlProvider.GetUrl(content.Id, true);
So a 'fun' way might be to write and inject your own UrlProvider.
A simpler way would be to create a new extension method which observes your url mapping.
UrlAbsolute/UrlWithDomain Issue
Hey!
I'm currently developing a site where I'm using custom routes and virtual content, the virtual content model inherits from PublishedContentModel in which I override the URL property to give my custom route rather than the wrapped contents URL. However when setting the canonical URL meta tag I use the UrlWithDomain() extension but this doesn't seem to use the overridden URL property to base it off. Is this by design or a bug? If by design is there some other method I can use to get this to work by any chance?
Cheers,
Tom
Hi Tom,
UrlWithDomain is an extension method of IPublishedContent rather than PublishedContentModel, so will use the original absolute URl instead of your modified one.
UrlWithDomain ultimately does this:
return UmbracoContext.Current.UrlProvider.GetUrl(content.Id, true);
So a 'fun' way might be to write and inject your own UrlProvider.A simpler way would be to create a new extension method which observes your url mapping.
This article may be useful for you:
http://24days.in/umbraco/2014/urlprovider-and-contentfinder/
Also, you will need to register your IUrlProvider implementation, by implementing IApplicationEventHandler.
In my case, I still want the DefaultUrlProvider, so In my OnApplicationStarting method, I would add
Where CustomUrlProvider is my implementation of IUrlProvider.
:)
Thanks Hywel makes sense now :)
is working on a reply...