Unable to change the URLSegment of a WritableClone

Leif Boström
Member since: 2002

I'm trying to change the URLSegment of a page programmatically, but it doesn't seem to work using the UrlSegment.CreateUrlSegment method on a writable clone.

Has anyone encountered this before? Is it a bug or by design?

A short code sample:

PageData writablePage = CurrentPage.CreateWritableClone(); writablePage.PageName = "New Page Name"; writablePage.URLSegment = EPiServer.Web.UrlSegment.CreateUrlSegment(writablePage); DataFactory.Instance.Save(writablePage,    EPiServer.DataAccess.SaveAction.Publish,     EPiServer.Security.AccessLevel.NoAccess);

This, on the other hand, works just fine:

PageReference parent = PageReference.StartPage; PageData myPage = EPiServer.DataFactory.Instance.GetDefaultPageData(    parent, "MyOwnPageType"); myPage.PageName = "My new page";   myPage.URLSegment = EPiServer.Web.UrlSegment.CreateUrlSegment(myPage); DataFactory.Instance.Save(     myPage,         EPiServer.DataAccess.SaveAction.Publish,     EPiServer.Security.AccessLevel.NoAccess);
#27426 Jan 29, 2009 15:42
  • Per Bjurström
    Member since: 1999
    Try to use GetUniqueURLSegment instead.
    #27429 Jan 29, 2009 17:22
  • Leif Boström
    Member since: 2002


    I tried that, but it returns the original URLSegment of the CurrentPage object. Can it be that the WritableClone is in an unsaved state causing it to fetch the old PageData object?

    #27432 Jan 29, 2009 19:20
  • Per Bjurström
    Member since: 1999

    I looked at the code and it will not regenerate the URLSegment if it already has a value, makes sense when used from edit mode but not when you call the function directly and it does nothing. Try setting URL Segment to null before you call the method, that should do the trick.


    #27434 Jan 30, 2009 9:01
  • Leif Boström
    Member since: 2002
    It did! Thanks for the help!
    #27441 Jan 30, 2009 10:42
  • valdis iljuconoks
    Member since: 2011

    Old but useful thread :) Just encounter the same issue..

    #66487 Mar 01, 2013 13:15