tif
tif

Reputation: 1149

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.

Upvotes: 1

Views: 2138

Answers (3)

tompipe
tompipe

Reputation: 949

There is a fantastic library of useful code to make working with EPiServer easier.

Download the EPiCode extensions library and add it to your project.

This has an extension method IsEPiServerPage which can be used. The method source is:

    public static bool IsEPiServerPage(this PageData page)
    {
        return page != null && page.PageLink != null && page.PageLink.ID > 0;
    }

Upvotes: 0

Johan Kronberg
Johan Kronberg

Reputation: 1086

It's not a good thing you got goin' but if you don't want to hook up your non EPi-pages to a real page instance of a separate page type I guess your best bet is to check Request.Url or the file name of the ASPX-file being processed.

Upvotes: 0

Dave Brace
Dave Brace

Reputation: 1809

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) {...}

Upvotes: 3

Related Questions