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

About the Author

Adnan Zameer, Lead Developer at Optimizley UK, is a certified Microsoft professional, specializing in web app architecture. His expertise includes Optimizley CMS and Azure, showcasing proficiency in crafting robust and efficient solutions.

0 comments :

Post a Comment