Dynamic content (MVC) get current page?

Vote:
 

How to get current page in dynamic content plugin?

Thanks.

#63362
Nov 16, 2012 8:26
Vote:
 

You can use PageRouteHelper class

var pageRouteHelper = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.Web.Routing.PageRouteHelper>();
PageReference currentPageLink = pageRouteHelper.PageLink;
PageData currentPage = pageRouteHelper.Page;

    

#63366
Nov 16, 2012 8:51
Vote:
 

Tried that, Episerver.Find cant index page if page route helper is used in dynamic content.

2012-11-13 20:33:58,194 [67] ERROR EPiServer.Find.Cms.ContentIndexer: An exception occured while indexing (Batch): Error getting value from 'MainBody' on 'Castle.Proxies.CompanyPageProxy'.. 
Newtonsoft.Json.JsonSerializationException: Error getting value from 'MainBody' on 'Castle.Proxies.CompanyPageProxy'. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> EPiServer.ServiceLocation.ActivationException: Activation error occurred while trying to get instance of type PageRouteHelper, key "" ---> StructureMap.StructureMapException: StructureMap Exception Code: 309
You cannot use the HttpContextLifecycle outside of a web request. Try the HybridLifecycle instead.

 

Exception can be catched of course, but maybe there is any other approach, that allows episerver find to index dynamic content.

#63368
Nov 16, 2012 9:02
Vote:
 

Apparently indexing is done outside the HTTP request so PageRouteHelper is useless in that case. In order to avoid try/catch you can just check if HttpContext.Current is null. 

#63373
Nov 16, 2012 10:27
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.