Frederik Vig – ASP.NET developer

Follow me

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.

Related Posts:

Share:
  • Twitter
  • DotNetKicks
  • DZone
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Digg

2 Comments

  1. Lars says:

    When would you not use the first approach?

  2. Frederik Vig says:

    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.

Leave a Reply

Spam Protection by WP-SpamFree

© Copyright Frederik Vig. Based on Fluid Blue theme