typesepiservercurrent-page

How to get the "Page type" for the current page. EPiServer


How can I get the Page Type for the current page. I tried

CurrentPage.GetType();

but no success. I need to check if the Page Type equals a specific type in order to do something or not.

Thanks


Solution

  • You need to check the PageTypeName or PageTypeID properties, like this:

    if(CurrentPage.PageTypeName == "StartPage")
        // Do something
    

    Check the reference: http://sdk.episerver.com/library/cms5/html/AllMembers_T_EPiServer_Core_PageData.htm

    The GetType() method is declared on System.Object and returns the System.Type for the object. Is is available on all types in the .NET Framework since all types inherit from System.Object.