Programatically add URL to pages. - General Discussions - General Discussions - Progress Community
 General Discussions

Programatically add URL to pages.

  • Programatically add URL to pages.
  • We're attempting to add an alternate URL to pages imported from Sitefinity 3.x so the that migrated site will accept URLs such as www.siteurl.com/contactus.aspx as well as www.siteurl.com/contactus but are having difficulty getting the additional URLs associated with the pages.  The entries are showing up in the database, but they do not work on the site front end and do not appear in the Additional URLs text box when editing page properties.  Any help that could be provided in this matter would be appreciated.

    if (urlName.ToLower().IndexOf(".aspx") == -1)
        pageUrlData = new PageUrlData();
        pageUrlData.Id = Guid.NewGuid();
        pageUrlData.Url = "~/" + urlName + ".aspx";
        pageUrlData.IsDefault = false;
        pageUrlData.ApplicationName = pageData.ApplicationName;
        pageUrlData.Disabled = false;
        pageUrlData.LastModified = DateTime.Now;
     
        pageNode.Urls.Add(pageUrlData);
  • Hello Michael,

    Please refer to the code sample attached bellow which demonstrates the fluent api behavior when creating pages with additional urls.  You can customize it anyway you want in order to fit it to your needs.

    var pageFacade = App.WorkWith().Page().CreateNewStandardPage(PageLocation.Frontend); 
        
                var additionalUrl = "~/mypageredirect1"; 
                pageFacade 
                    .Do(p => 
                     
                        p.Name = "mytest3"; 
                        p.Title = "mytitle3"; 
                        p.UrlName = "myurl"; 
                        p.ShowInNavigation = true; 
                        p.LastModified = DateTime.UtcNow; 
                        p.DateCreated = DateTime.UtcNow; 
                        p.Page.Title = "myname3"; 
                        //set title which appears in page header 
                        p.Page.HtmlTitle = "mytitle3"; 
                        p.Description = "mydesc3r"; 
                        p.AllowMultipleUrls = true; 
                        pageFacade.PageManager.AddPageNodeAdditionalUrl(p, CultureInfo.InvariantCulture, additionalUrl, false); 
        
                    ); 
                pageFacade.SaveChanges(); 
        
                SiteMapBase.Cache.Flush();

    Greetings,
    Victor Velev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items