1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Add urls to programmatically created pages

Add urls to programmatically created pages

2 posts, 0 answered
  1. Andrew
    Andrew avatar
    6 posts
    Registered:
    26 Jul 2007
    07 Aug 2007
    Link to this post
    Hello

    If I create a page with code then how do I go about adding friendly urls to it?

    At the moment I am creating (Nolics)  CmsUrl objects and then adding them to the
    ICMSPage's  list of urls. This seems wrong to me as I am directly accessing the data layer

    is there a better way to do this?


  2. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    08 Aug 2007
    Link to this post
    Hello Andrew,

    Here is a better way to add additional URL to a ICmsPage using Cms interfaces:

    using Telerik.Cms;     
    using Telerik.Cms.Web;     
       
    ...     
        
        string url = "~/HomeFriendlyUrl.aspx";     
        
        // Add the URL only if it does not exists in the site     
        ICmsUrlContext urlContext = UrlHelper.GetUrl(this.ResolveUrl(url).ToLower(), true);     
        if (urlContext == null)     
        {     
            CmsManager manager = new CmsManager();     
            ICmsPage page = manager.GetPage(pageId, true);     
            page.AddUrl(url);     
            manager.SavePage(page);       
        }    
     


    Greetings,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
2 posts, 0 answered