Maybe you can change can do it through umbracoSettings.config
<requestHandler>
<!-- this will ensure that urls are unique when running with multiple root nodes -->
<useDomainPrefixes>true</useDomainPrefixes>
<!-- this will add a trailing slash (/) to urls when in directory url mode -->
<addTrailingSlash>true</addTrailingSlash>
</requestHandler>
This will make sure that a domain is included in the url and that the url has a trailing slash. So you don't need to do that in your urlprovider.
I believe that including the domain, for canonical, in the url is only in view, template, partial view, etc. UrlProvider is for the URL after the domain. Also because there could be multiple domains and doing so in UrlProvider would bring problems. I may be wrong. I am used to doing canonical in view with razor.
Ok after some scrolling into the Umbraco code I have now implemented a complete custom IUrlProvider where I check the UrlProviderMode to know if the request needs the domain prefix or not.
This is working fine, but I now need to check the UseDomainPrefixes property which can be accessed by the IRequestHandlerSection.
But if I implement this using the constructor like the DefaultUrlProvider then the .GetUrl is never called.
yes I got it working but it has been a pain in the ass!
Also its not a perfect solution, because I had to copy code from the core because it was all internal ( so not possible to use it for custom providers ).
Was already looking to make a PR for this to make it more useable but haven't got the time yet to make it work.
Okay - I was fortunate that my custom UrlProvider used the parent node's URL as its base, so I was able to pass the provided UrlProviderMode argument along when getting that, so it just magically worked.
But other UrlProviders may not always be able to do that...
NiceUrlWithDomain issue using custom UrlProvider
Hi all,
on my master page I need to set a canonical url for some pages because we can have multiple urls pointing to the same content.
For most pages it is working fine but for my
Categories
andCompanies
, which are using custom urls by defining a custom UrlProvider this doesn't work.I only get for instance:
/categorie-1/
or/company-1/
so the domain isn't defined.Below are my url providers:
Compagnies
Categories
Registrating url providers and contentfinders
Anyone that can help me out here?
Is there a way to know in the url provider when the url needs to be prefixed by the domain of the website and how can I get this domain?
/Michaël
Hi Michaël,
Maybe you can change can do it through umbracoSettings.config
This will make sure that a domain is included in the url and that the url has a trailing slash. So you don't need to do that in your urlprovider.
Dave
Hi Dave,
sorry for the late response.
I have tried this but this doesn't work. It still keeps showing the url without the domain.
Any ideas?
/Michaël
I think for getting the full url you need to set a domain on your root node
Dave
Hi,
I can not tell you why NiceUrlWithDomain is not working. Does this happen in the development environment? localhost?
For canonical, in razor do this:
Hi Marcio,
I am implementing custom UrlProviders which are included before the nice url provider.
So that why it only shows the
/categorie-1/
or/company-1/
url.I was also thinking of using this but I would like to know how this can be done in the url provider instead of doing it in the view.
/Michaël
I believe that including the domain, for canonical, in the url is only in view, template, partial view, etc. UrlProvider is for the URL after the domain. Also because there could be multiple domains and doing so in UrlProvider would bring problems. I may be wrong. I am used to doing canonical in view with razor.
Hi Marcio,
the complete url is rendered by the UrlProvider.
I have found that it passes a param called
UrlProviderMode
which indicated weither the url needs the domain prefix or not.The only issue is catching the umbraco settings config file to get the value of the
UseDomainPrefixes
./Michaël
Ok after some scrolling into the Umbraco code I have now implemented a complete custom IUrlProvider where I check the
UrlProviderMode
to know if the request needs the domain prefix or not.This is working fine, but I now need to check the
UseDomainPrefixes
property which can be accessed by theIRequestHandlerSection
.But if I implement this using the constructor like the
DefaultUrlProvider
then the.GetUrl
is never called.I also see that
IRequestHandlerSection
is implemented by theRequestHandlerElement
, which is internal.So we can't access this in our project.
Seems like we get stuck here to get a full working custom url provider.
/Michaël
Hi Michaël,
Were you ever able to "fix" this and have your custom
UrlProvider
work forNiceUrlWithDomain()
?/Chriztian
Hi Chriztian,
yes I got it working but it has been a pain in the ass!
Also its not a perfect solution, because I had to copy code from the core because it was all internal ( so not possible to use it for custom providers ).
Was already looking to make a PR for this to make it more useable but haven't got the time yet to make it work.
/Michaël
Okay - I was fortunate that my custom
UrlProvider
used the parent node's URL as its base, so I was able to pass the providedUrlProviderMode
argument along when getting that, so it just magically worked.But other UrlProviders may not always be able to do that...
/Chriztian
I will try to make a blog post about the problem and solution and add it here so others can use it.
Maybe then you can add your solution also about using the parent node url.
I will keep you posted!
/Michaël
Blog posted here http://www.ucodebase.be/blog/implementing-a-custom-urlprovider-in-umbraco-and-its-pitfalls/
/Michaël
is working on a reply...