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


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?

Feb 26, 2018 16:04
            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?

Feb 26, 2018 16:13

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

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.