EPiServer.DataFactory.Instance.CurrentPage

Vote:
 

It is common for me to need to get the CurrentPage from a piece of code where it isn't available as a page property e.g. within a masterpage.

 

I initial tried
    EPiServer.DataFactory.Instance.CurrentPage
but this always returns null.

 

So have been using
    EPiServer.PageBase PB = HttpContext.Current.Handler as EPiServer.PageBase;
    EPiServer.Core.PageData aCurrentPage = PB.CurrentPage;
And this seems to work okay.

My question is what's the intended use of
    EPiServer.DataFactory.Instance.CurrentPage
and why does it always return null.

#42480
Aug 25, 2010 10:51
Vote:
 

See the SDK page: http://sdk.episerver.com/library/cms6/html/P_EPiServer_DataFactory_CurrentPage.htm

I suppose its kept there as a general concept which can be used by other page sources than the standard DataFactory (I imagine some kind of sequential source which allows access to the most recent page, or something like that).

#42482
Aug 25, 2010 11:06
jo
Vote:
 

Nah, its simply so that the property is part of the interface IPageSource, so it has to be implemented even though it has no "meaning" for the DataFactory (as it has no concept of a "CurrentPage")

I would however seen that the implementation simply throwed an exception with a clear text describing why you shouldnt call it.

/johan

#42489
Aug 25, 2010 11:31
Vote:
 

That's what I meant, my imaginary sequential source would be a different implementation of IPageSource where it HAS meaning, and a meaning specific to that page source.

#42492
Aug 25, 2010 11:53