How to Determine the current page from the current block on that page?

Ayo
Ayo
Vote:
 

Hi Guys,

I have a block on a page in Episerver, (content area) - from within the controller for the block how can I determin the node that represents the page that this block appares?

#188517
Feb 26, 2018 16:04
Ayo
Vote:
 
            var pageRouteHelper = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IPageRouteHelper>();
            var currentPage = pageRouteHelper.Page;



I found this as an answer to a similar question and its working for me, - however this is my very first Episerver project, and would just like confirmatoin, that this is the "best practice way" to do this?

#188518
Feb 26, 2018 16:13
Vote:
 

As far as best practice goes it is to build your blocks so that they don't need to know which page they are on. embarassed

#188602
Feb 27, 2018 17:05
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.