Developer forum

Forum » Development » Get page based on the friendly URL

Get page based on the friendly URL

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

HI guys,

Is there any method to find a Page based on the Friendly URL?

Thank you,

Adrian


Replies

 
Nicolai Pedersen
Reply

It depends on what your URL looks like.

If you have a path that is just for a page in the page tree, i.e. pageName/subpage/somepage, you can use this code:

UrlIndex.AwaitIndexBuild()
Dim curArea As Area = PageView.GetAreaByDomain()
Dim index As UrlIndex = UrlIndex.GetIndex(UrlPageTreeHelper.Instance.GetAreaUrlIndexName(curArea))

Dim resultingQuerystring As String = String.Empty
If index.PathIndex.ContainsKey(requestPath) Then
    resultingQuerystring = index.PathIndex.Item(requestPath).GetQueryString()
End If

If you have a URL with groups and products, you cannot - there is a lot of code and it currently redirects, so you cannot get back a page id or something similar. But I can give you the code to tear appart if you need it...

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you for the reply.

I will try to work with it.

What I am trying to accomplish is an automatic redirect to an Area based on the Browser settings (language).

And I can think of scenarios where the user might land on a specific link that in most cases would be the friendly URL.

My current project is using mostly pages but I can expect that they would want to cover products and groups in the future.
We'll handle it when we get there.

Thank you,
Adrian

 
Nicolai Pedersen
Reply

Hi Adrian

If you are in c# code, the url is already converted into Dynamicweb formats. So if you just want to make redirects using accept language, you can simply do that using the languages loop.

Also, you should be careful with fully automatic redirect - it can be really anoying. Many sites detect your language or country by ip, and suggest in the browser to go to the correct version of the site.

 

You must be logged in to post in the forum