episervercurrent-page

How to differentiate if the current page is an EPiServer Page or not


I need to know if the current page is an EpiServer page or not. I need to know if the current page is the start page, I am using the following line of code.

if(PageReference.StartPage.ID == CurrentPage.PageLink.ID)

This works perfect on all EPiServers, but when I am on a non EPiServer page then CurrentPage returns values for the StarPage. This means that all my non-EPiServer pages are treated as a StartPage (just in my if statement of course).

One solution I thought of is to check first if the page is an EPiServer page? But don't know how to do this. Can I get the class for a page or how can I achieve this?

Any ideas or suggestions?

Thanks in advance.


Solution

  • Are your non-EPiServer pages just custom aspx pages? If this is the case you have problems with you can check if the current page inherits from an EPiServer page by checking the Page's type. I believe all EPiServer pages inherit from PageBase.

    if (Page is EPiServer.PageBase) {...}