Thursday, 2 October 2014

How to Get Current Page in Dynamic Content Plugin or from Controller in EPiServer

If you want to get the current page in a block controller or from an ActionFilter, you can use EpiServer PageRouteHelper class
Getting The Page Object
using EPiServer.ServiceLocation;

var pageRouteHelper = ServiceLocator.Current.GetInstance< EPiServer.Web.Routing.PageRouteHelper>();
var currentPage = pageRouteHelper.Page;
Getting A Page Reference
using EPiServer.ServiceLocation;

var pageRouteHelper = ServiceLocator.Current.GetInstance< EPiServer.Web.Routing.PageRouteHelper>();
var pageReference = pageRouteHelper.PageLink;
you can also use the following code in the block or pagetype to achieve the above
var pageRouteHelper = ServiceLocator.Current.GetInstance();



/Adnan

0 comments :

Post a comment