Programatically add URL to pages.

Posted by Community Admin on 03-Aug-2018 23:39

Programatically add URL to pages.

All Replies

Posted by Community Admin on 11-May-2011 00:00

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);

Posted by Community Admin on 12-May-2011 00:00

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

This thread is closed