Try our conversational search powered by Generative AI!

PublishedContent event and UrlResolver problem


I have a problem with the PublishedContent event and UrlResolver. I have added a method to the PublishedContent event to handle a page of type container page. I the container page has an updated url segment I want to get all the new urls for the child pages. However when i try urlResolver. GetUrl(child) the returned string till has the old container page urlsegment in it.


ContainerPage url segment from "container1" to "container2" -> publish

in method urlResolver.GetUrl(child) then returns "container1/child" instead of "container2/child".

If I try urlResolver.GetUrl(childpage) later the returned string is correct so im guessing this have to do with the url segment not updating untill after the publishedContent event is done. 

Has anyone hade experience of this and found a solution?

Any help would be most appreciated :)

Mar 07, 2016 14:53

Tried reacting to the CreatedUrlSegment event?

Set up in initializable module.. 

public void Initialize(InitializationEngine context)
UrlSegment.CreatedUrlSegment += UrlSegmentOnCreatedUrlSegment;

private void UrlSegmentOnCreatedUrlSegment(
object sender, UrlSegmentEventArgs urlSegmentEventArgs)
var segment = urlSegmentEventArgs.RoutingSegment.RouteSegment;
...kill hyphens, shorten the urlsegment, to lower etc...

If that doesn't work let me know and I'll check some source code where I solved that one a few years ago.. 

Mar 07, 2016 15:56

Thanks for the advice. Unfortunatly if im not mistaken the CreatedUrlSegment event is only fired when the segment is created the first time. I also need to act on urlsegment changes and if the url segement of the page is changed the event is not fired. 

Please check if you can find anything or if you have any other idea. 

Tahnks for the help!

Mar 07, 2016 17:59

The evicting of cache entries for url segments are also triggered by events from IContentEvents. It appears that your event handler is registered before the event handler that evicts cache entries. To ensure your cache handler is registered after the one eveicting from cache a suggestion is to hook up your eventhandler inside an IInitializableModule.Initialize method that has a ModuleDependency attribute set to EPiServer.Web.InitializationModule.

Mar 08, 2016 11:44

...or move logic to publishing event and check the updated item vs the one that already exist

private void InstancePublishingPage(object sender, PageEventArgs e)

var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
var contentReference = new ContentReference(e.Page.ContentLink.ID);
if (!ContentReference.IsNullOrEmpty(contentReference))
var languageSelector = new LanguageSelector(e.Page.LanguageID);
var page = contentLoader.Get<PageData>(contentReference, languageSelector);
if (page != null && page.URLSegment != e.Page.URLSegment)
var pages = _contentService.GetDescendents(page.PageLink, true, languageSelector);


...or install SEO Manager that will automatically create 301s if you do something like that. :)

Edited, Mar 08, 2016 11:59

Thanks alot Johan that seems to work! 

You are right Daniel this should hopefully never happen but you never know with editors :)

Mar 08, 2016 16:53

More likely they will move stuff around in the tree which will be the same problem from a SEO perspective.

Mar 08, 2016 17:53
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.