More in this section

Forums / Developing with Sitefinity / Changing a Page URL

Changing a Page URL

5 posts, 1 answered
  1. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    28 Sep 2009
    Link to this post
    I'm trying to change the first additional URL but it keeps throwing an exception: "You cannot change a value of an object that is not in transaction."

    I'm passing true to GetPage but it doesn't make a difference.

    Here's what my code looks like now. Can you show me how to fix it?
                ICmsPage ThePage = (ICmsPage)cmsManager.GetPage(new Guid("1fdd25eb-a261-445e-bc99-e572dc54b258"), true); 
                // This causes object not in transaction exception
                ((CmsUrl)ThePage.Urls[0]).Url = "~/ModifiedUrl-UniqueID" + Guid.NewGuid().ToString() + ".htm"
     

    Thanks,
    Jeff
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    29 Sep 2009
    Link to this post
    Hi Jeff,

    Try using the code sample shown below:

            CmsManager manager = new CmsManager();  
            ICmsPage page = (ICmsPage)manager.GetPage(new Guid("4f902dd6-d8d3-4b03-be6b-d62d877a876a"), true);  
            page.AddUrl("~/testURL.aspx");  
            manager.SavePage(page); 

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    29 Sep 2009
    Link to this post
    Hi Ivan,

    I was asking how to modify an existing URL, not add a new one.

    I'm using the first additional URL as the primary URL to access the page due to the limitation we previously discussed. It is crucial that I am able to modify it.

    Can you please help me find a way?

    Thanks,
    Jeff
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    29 Sep 2009
    Link to this post
    Hi Jeff,

    1. The code I sent you works. Add it to a simple control and run your debugger.

    2. Please try the code below:

            var manager = new CmsManager(); 
            ICmsPage page = (ICmsPage)manager.GetPage(new Guid("EFA6BFA4-9C88-4ECF-A978-0ACA1E265B06"), true); 
            IList<ICmsUrl> urls = page.GetUrls(); 
            string additionalUrl = "~/test.aspx"
            urls[0].Url =  additionalUrl; 
            manager.SavePage(page); 

    Attached is a screencast that illustrates what the control does.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  5. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    29 Sep 2009
    Link to this post
    Wonderful! That worked like a charm.

    Sorry about claiming your AddUrl code didn't work. I realized it was my mistake (forgot the SavePage call) and removed that from my post within 2 minutes of writing it. You must have got to my post before the edit.

    Thanks again for your help.

    Jeff
Register for webinar
5 posts, 1 answered