Master Pages and EPiServer CurrentPage property
When 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.
When would you not use the first approach?
Hi 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.