How to get current page in dynamic content plugin?
You can use PageRouteHelper class
var pageRouteHelper = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.Web.Routing.PageRouteHelper>();
PageReference currentPageLink = pageRouteHelper.PageLink;
PageData currentPage = pageRouteHelper.Page;
Tried that, Episerver.Find cant index page if page route helper is used in dynamic content.
2012-11-13 20:33:58,194  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: 309You 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.
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.