Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Getting handle on CurrentPage/PageBase from within PagePlugIn

Vote:
 

Hi all,

I've developed a PagePlugin so that we can carry out some HTMLRewriting of hyperlinks - we are modifying the markup EPiServer spits out if the hyperlink is to a binary asset such as a PDF/DOC/DOCX.

This works fine, however the requirements have changed slightly and now we need to be able to turn this functionality on/off on a page by page basis. As we have developed a PagePlugin I thought we should be able to implement the ICustomPluginLoader and then cast the current handler to PageBase, and then check for a property on the page i.e. check whether the HTMLRewriting property (true/false) has been disabled. However, within the List() member of the ICustomPluginLoader HttpContext.Current.Handler always returns null, just as it does within the Initialize method of the PagePlugin.

Does anyone have any thoughts on how I can get access to the Current Page, or even the current handler (so it can be cast to a PageBase object) from within the PagePlugin?

Thanks in advance

Al

#75580
Sep 30, 2013 15:46
Vote:
 

You should be able to use the PageRouteHelper to get the CurrentPage:

var pageRouteHelper = ServiceLocator.Current.GetInstance<PageRouteHelper>();
PageData currentPage = pageRouteHelper.Page;

    

#75583
Sep 30, 2013 16:28
Vote:
 

Hi Chris,

Thanks for your response. Unfortunately this too returns null - both the PageLink and Page proeprties of pageRouteHelper are null.

Really scratching my head on this one....

Al

#75584
Sep 30, 2013 16:44
Vote:
 

Is this EPi 7 using MVC or WebForms?

#75586
Sep 30, 2013 16:50
Vote:
 

Hi Chris,

It's using WebForms...

Al

#75587
Sep 30, 2013 16:53
Vote:
 

I'm trying to use this i MVC, and I also get null from using Chris's code.

#82179
Mar 06, 2014 15:02
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.