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

Forums / Developing with Sitefinity / Multiple page URLs

Multiple page URLs

4 posts, 0 answered
  1. D.
    D. avatar
    4 posts
    Registered:
    05 Jun 2008
    02 Jul 2008
    Link to this post
    I have the following structure of pages:
    MainGroup.aspx (Page group)
    |_HeadPage.aspx (Page group)
        |_PageA.aspx(Page)
        |_PageB.aspx(Page)
    Since I don't want the URL to contain /MainGroup/, I defined custom URLs for each of the other three pages. If I navigate directly to PageA, from a menu for example, the URL in the Address bar is fine:
    http://MySite/HeadPage/PageA.aspx.
    If I navigate to HeadPage, I am redirected to PageA, as expected, but the URL in the Address Bar is:
    http://MySite/MainGroup/HeadPage/PageA.aspx
    which is the automatically generated URL. Is it possible to somehow make the PageGroup to redirect to the URL of the first subpage that is selected as Default URL?
  2. Nikifor
    Nikifor avatar
    232 posts
    Registered:
    18 May 2013
    03 Jul 2008
    Link to this post
    Hello D.,

    This could be achieved but it is not a really easy task. There are several steps which should be followed for overriding the CmsSiteMapProvider. Please follow the instructions below:

    • Create your CustomCmsSiteMapProvider class in the App_Code folder of your Web site:
    using Telerik.Cms;   
    using Telerik.Cms.Web;   
      
    /// <summary>   
    /// Summary description for CustomCmsSiteMapProvider   
    /// </summary>   
    public class CustomCmsSiteMapProvider : CmsSiteMapProvider   
    {   
        protected override CmsSiteMapNode CreateSiteMapNode(ICmsPage page)   
        {   
            return new CustomCmsSiteMapNode(this, page);   
        }   
    }   
      
    public class CustomCmsSiteMapNode : CmsSiteMapNode   
    {   
        public CustomCmsSiteMapNode(CustomCmsSiteMapProvider provider, ICmsPage page)    
            : base(provider, page)    
        {    
        }   
      
        public override string Url   
        {   
            get  
            {   
                // Add your logic for changing the URL   
                return base.Url;   
            }   
            set  
            {   
                base.Url = value;   
            }   
        }   
    }   
      

    •   Change the default SiteMapProvider with your custom one in the web.config:

      <system.web> 
        ...  
        <siteMap defaultProvider="CmsSiteMapProvider" enabled="true">  
          <providers> 
            <clear /> 
            <add name="CmsSiteMapProvider" description="Displays Cms Pages" type="CustomCmsSiteMapProvider" /> 
          </providers> 
        </siteMap> 
     
     
    •   Enable the URL Rewriter for the project and create rewriting rule matching your scenario using Regular Expressions. For more information about doing this please check the User Manual section URL Rewriting

    Hope this helps.

    Greetings,
    Nikifor
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. D.
    D. avatar
    4 posts
    Registered:
    05 Jun 2008
    03 Jul 2008
    Link to this post
    Actually, I am not using the CmsSiteMapProvider. That is why I need to implement a solution that reads the pages and generates menu items for them in a menu that is using a web.sitemap-based Sitemap. Is it possible to set the urlRewriteFormat in runtime and is this going to affect hte redirecting functionality in a PageGroup?
  4. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    08 Jul 2008
    Link to this post
    Hi D.,

    You can use the Sitefinity API to generate the node items for you custom SiteMap. Here is a code example how you can get CMS pages:

    public SiteMapNode BuildSiteMap() 
        lock (this
        { 
            if (this.root != null
                return this.root; 
     
                    CmsManager manager = new CmsManager(); 
            IRootPage rootPage = manager.GetRootPage(); 
            this.root = new  CmsRootSiteMapNode(this, rootPage); 
            foreach (ICmsPage page in rootPage.Pages) 
            { 
                            // Create and add SiteMapNode, and call LoadPagesRecursive recursively 
                SiteMapNode node = CreateSiteMapNode(page); 
                if (node != null
                { 
                    AddPageNode(node, this.root); 
                    this.LoadPagesRecursive(node, page); 
                } 
            } 
     
            return root; 
        } 
     
    private void LoadPagesRecursive(SiteMapNode parentNode, ICmsPage parentPage) 
        foreach (ICmsPage page in parentPage.Pages) 
        { 
                    // Create and add SiteMapNode, and call LoadPagesRecursive recursively 
            CmsSiteMapNode node = CreateSiteMapNode(page); 
            if (node != null
            { 
                AddPageNode(node, parentNode); 
                this.LoadPagesRecursive(node, page); 
            } 
        } 
     


    As for the Url Rewriting, you can create your regular expression rules to rewrite URLs in runtime. For more information about this, please check the User Manual section URL Rewriting.

    Hope this is helpful.

    Greetings,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
4 posts, 0 answered