EpiServer how to get the URL of a link to a specific page?

I need to link the LinkURL of the blog page with the link on the start page. In fact, I found that the page ID and get a link to the page using it.

PageReference BlogPageReference = new PageReference(21); PageData BlogPage = GetPage(BlogPageReference); var url = BlogPage.LinkURL; 

This is pretty straight forward, but I'm unhappy that the page id is hardcoded. Is there a better way to do this, for example, getting the page name by page? or any other way?

Thank you in advance:)

+6
source share
1 answer

I would create a property on the start page of type "Page", which means that the property will be of type PageReference. Then it is no longer hardcoded.

It is also common to move such β€œsettings” properties to a separate type of settings page, which itself is connected through a property from the root or the initial page (which are constants).

I am writing from memory, so I apologize for any errors in the code.

 var startPage = DataFactory.Instance.Get<StartPage>(PageReference.StartPage); var settingsPage = DataFactory.Instance.Get<SettingsPage>(startPage.SettingsPage); var blogPageRef = settingsPage.BlogPage; 

If SettingsPage and BlogPage are defined

 public virtual PageReference xxxPage {get; set; } 

in your page type class.

+9
source

Source: https://habr.com/ru/post/953304/


All Articles