Master Pages and EPiServer CurrentPage property
Posted on May 20, 2009 by Frederik Vig in Code Snippet, EPiServerWhen you use user controls or web forms in your EPiServer web application you usually inherit from either UserControlBase or TemplatePage. Which gives you, among other things, the CurrentPage property. The problem is when you need the CurrentPage property in your Master Page.
The way I usually fix this is with this code.
var page = (PageBase) Page; ... page.CurrentPage.PageName; page.CurrentPage.LinkURL; ...
This should work fine in both EPiServer 4 and 5.

Lars says:
Post Author December 8, 2009 at 13:37When would you not use the first approach?
Frederik Vig says:
Post Author December 20, 2009 at 14:29Hi Lars
To be honest I would always use the first approach. After re-reading the code, I’ve come to the conclusion that there is no point keeping both. I’ve now deleted the other method. Stick with casting the Page object to PageBase.
camion says:
Post Author April 14, 2011 at 17:09This is very interesting post. I really liked it. Please keep posting such an informative post