EPiServer 7 : How do I get the “CurrentPage” from a controller ?

I’ve had a few instances where I’ve needed to get the current page in a block controller or from an ActionFilter, so I thought I’d add a link to say:

Getting A Page Reference

var pageRouteHelper = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.Web.Routing.PageRouteHelper>();
var pageReference= pageRouteHelper.PageLink;

Getting The Page Object

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

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

2 replies

Trackbacks & Pingbacks

  1. […] wizardry with communication between blocks on your product pages. One of my most popular tutorials EPiServer 7 : How do I get the “CurrentPage” from a controller ? deals with a similar […]

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *