Developer forum

Forum » Development » Get ID of page by "search engine friendly url"

Get ID of page by "search engine friendly url"

Emil Ryberg
Reply

Hi,

Is it possible to get the internal Page ID of a page by supplying a method with the "search engine friendly url", eg. "/products/thisproductcategory".
I have tried using Dynamicweb.Base.GetInternalPageID and Dynamicweb.Frontend.DirectPath.Path.GetPathByUrl, but it does not return a page. Can i use these methods, if yes how do i format the URL to make sure it returns the correct data?

 


Replies

 
Emil Ryberg
Reply

Would appreciate to get some feedback on this.

 
Martin Vang
Martin Vang
Reply

Hi Emil,

I've taken a look at those methods, and you cannot use any of them. Also, I've been unable to find anything in our api that allows you to do what you describe - maybe you can explain what you're trying to achieve, and I can come up with a hint for how it can be solved in a different way?

BR

Martin

 
Emil Ryberg
Reply

Hi Martin,

That is unfortunate. I just need it to check if the page actually exists. I could of course make a HTTP request to the URL, but that is just going to add unneccesary overhead.
There must be a better way to do it in DW?

/Emil

 
Martin Vang
Martin Vang
Reply

How do you get the url to start with? Guess? Can you describe the scenario you're facing in a bit more detail? I'm fairly certain that you can rethink this problem in a way that is already supported. :)

BR

Martin

 
Emil Ryberg
Reply

We have a website with a site for non-logged in users and a site for logged in users. If an user is on the non-logged in site on a product page for example and logs in, it should check if the page also exists on the logged in site and thereafter redirect to it. The reason I'm using URL is because the logged in site uses "{DOMAIN}/erhverv/{Rest of url}" so therefore i should only have to prepend the URL with /erhverv/ if it exists.

/Emil

 
Martin Vang
Martin Vang
Reply

Alright I have 3 different suggestions for how you can resolve this.

1. One page with seperate logic for logged on vs not logged on. Use permissions to show / hide as needed.

2. Redirect user on log on.

3. Use language layer with fx. Danish master (not logged in)-> Danish child (logged in). Then you can use the Languages or WebsiteLanguages loops (dont recall which one), and redirect IF the page exists as a "language version".

 

I've ordered them by which solution I think is most clean. Hope one of them can solve your problem.

BR

Martin

 
Emil Ryberg
Reply

The pages for logged in and not logged are children of 2 pages; 1 for non-logged in users and 1 for logged in users. The point is to redirect users on log on, but the problem is to figure out if the URL actually exists..

 
Nicolai Pedersen
Reply

Hi Emil

Why do you need to look up the path/url to a page? You always have the id of the current page accesible and cand do what you want. Likewise, links to other pages always comes as Default.aspx?ID=123 when on the server, so you again do not have (or should have) a full URL.

Urls are only some rewriting on the way in and out of the server that you very rarely should take into consideration.

Maybe post your entire code for us to see - I think you can do it much simpler.

BR Nicolai

 
David Alexandersson
Reply

I have a similar problem! 

The id of a page is different in different language layers, so this code: 

<li>
 <a href="Default.aspx?ID=7">@Translate("My Page")</a>
</li>

Will always take me to the english version of "My Page"..

 

What is best practice here? Is there another way of creating links that are more dynamic? 

 
Nicolai Pedersen
Reply

Hi David

You have 2 options - you can either loop the language version of the pages or use "Navigation tags" - see link in the example below. You usually would never want to use URLs to parse information.

Option 1

            //Find the page in the master language and loop its language versions
            var myHomePage = Services.Pages.GetPage(1);
            foreach(var languageVersionsOfHomePage in myHomePage.Languages)
            {
                //If one of the language versions of the page matches the current area, use the id and name for a link or something.
                if(languageVersionsOfHomePage.AreaId == Dynamicweb.Frontend.PageView.Current().AreaID)
                {
                    var name = languageVersionsOfHomePage.MenuText;
                    var id = languageVersionsOfHomePage.ID;
                }
            }

Option 2

            //Using navigation tags, see http://doc.dynamicweb.com/documentation-9/content/content/pages#3241, to get a language context based page
            var myLanguageContextHomePage = Services.Pages.GetPageByNavigationTag(PageView.Current().AreaID, "MyHomePage");

Hope this helps.

BR Nicolai

 

You must be logged in to post in the forum