I have two sites, USA and UK and a control which picks up a user's location.
How do I override Umbraco so when I get the users location it redirects to the appropriate site? By that if the user location is USA it goes to USA and if UK it goes to UK.
I have the country from the IP address but could I just create a user control and then write an if statement to say if the country is xx then response.redirect("example.com/cc") and place this on my home template as a macro?
Asembli - any reason why you would use IContentFinder over the web user control as a macro? For Umbraco 7 webform.
The macro seems more easier but if there is a benefit id like to know for future please? When I researched this, it only shows code with Asp net Core. I don't know how I would go about using this.
The best place to do this is HTTP module because then this logic would execute before Umbraco, this is in terms of performance.
Also, good place TryFindContent, because then this logic would execute before the page loaded - so it's faster then macro on the page that executes during page load.
Redirect user to site
Hi
I have two sites, USA and UK and a control which picks up a user's location.
How do I override Umbraco so when I get the users location it redirects to the appropriate site? By that if the user location is USA it goes to USA and if UK it goes to UK.
Thanks
A possible idea is to redirect on page load? If that's the case does anyone know if this is bad for SEO?
Any help would be great.
Hi, Colin,
you can place your redirection code in DefaultController - you can overwrite the Umbraco default controller and do the redirect there. I have done this several times. Here is the documentaion: https://our.umbraco.com/documentation/implementation/default-routing/Controller-Selection/
I hope that this will help.
Hi Mila
I've seen that link but it targets MVC which I'm not using for Umbraco 7. Is there another way?
Thanks
Hi Colin, you can redirect based on IP address
There are a few external services that can help to identify the country by IP address like https://ipstack.com/
Thanks, Alex
Hi Alex
I have the country from the IP address but could I just create a user control and then write an if statement to say if the country is xx then response.redirect("example.com/cc") and place this on my home template as a macro?
Many thanks
Hi Colin,
Yes, you can.
Hi,
or implement this in IContentFinder class inside
TryFindContent(PublishedContentRequest contentRequest)
there trap IP or browser lang and make redirect.
/Asembli
Thank you gents.
Asembli - any reason why you would use IContentFinder over the web user control as a macro? For Umbraco 7 webform.
The macro seems more easier but if there is a benefit id like to know for future please? When I researched this, it only shows code with Asp net Core. I don't know how I would go about using this.
Thank you
The best place to do this is HTTP module because then this logic would execute before Umbraco, this is in terms of performance.
Also, good place TryFindContent, because then this logic would execute before the page loaded - so it's faster then macro on the page that executes during page load.
Macro - probably slowest way.
Thank you very informative.
I have a class library project but how do I implement this in to have the existing functionality working as is but introducing this feature please?
I'm using Umbraco 7 forms and finding it difficult to get the correct dlls and code working.
1) IContentFinder example - https://our.umbraco.com/Documentation/Reference/Routing/Request-Pipeline/IContentFinder-v7
2) HTTP module example - https://www.codeproject.com/Articles/32475/Asp-net-HTTP-Modules
Hi Colin,
Please, let us which way you go and how did you solve the issue.
Thanks,
Alex
is working on a reply...