问题
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.
回答1:
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) {...}
回答2:
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.
回答3:
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;
}
来源:https://stackoverflow.com/questions/5820493/how-to-differentiate-if-the-current-page-is-an-episerver-page-or-not