Get URL to Page/Category/Product


I got a website where i want to switch language and it redirects to same page on that language.

We got it setup that each language got a channel:

So if I am on page: hostname/en/about-us i want to redirect to: hostname/sv/om-oss.

I have done this by using:

  • requestModel.CurrentPageModel.SystemId
  • PageService
  • ChannelService
  • UrlService

Though when a user is on a category or product page the SystemId above will not point to that “Page”.

I’m thinking i need to get the Category and BaseProduct Ids somehow and use respective service to then use with UrlService? How would i go for that the best way, or is there another service where i can transform from currentUrl => “page”.

Thanks in advance.
Best Regards
Artur O.

Litium version: 7.2.3

Is the redirect generated as a link with the mapped URL or when do you resolve it?

If it’s generated you could maybe pass CategoryModel and ProductModel into the controller action and work out the URL you want from there.

Another option could be to inject the RouteRequestInfoAccessor and cast its .RouteRequestInfo.Data as ProductPageData

1 Like


Currently I have implemented this as API that consumes Guid of current page, target lang that returns full url to new page.

It is called when user tries to switch language using an dropdown.

Guid that i pass is generated when Header.cshtml is loaded.

Update, did something like you proposed thanks!
For future references:

Header.cshtml contains HeaderViewModel.

Added PageType Enum and GuidPageId that I then populate in cshtml for the dropdown.

And resolve it on the API side to respond with the pageurl with the above formentioned methods.

In general, don’t use the ‘HttpContect.Current’ to find information, use the ‘*Accessors’ classes instead to not get breaking changes in you application if the internal storage for them is changed.

1 Like

Great, thanks will have that in mind.

I also see that I missed to mention, I used the PageModel, CategoryModel, ProductModel in LayoutController to get the Id’s I wanted to the HeaderViewModel that is used for header.cshtml.

1 Like