Create internal redirect page with the native API
-
Get an instance of the
PageManager.
Like standard pages, internal redirect pages are also manipulated by thePageManager. To work with a group page, you need to get an instance of the manager. -
Set the parent of the page.
You can add the page under any other page by passing theparentPageNodeIdas an argument. If you pass an empty GUID the new page is created on root level. -
Create the page.
You create new page using theCreatePagemethod of thePageManager. The method has two overloads. Set the last parameter of the method toNodeType.InnerRedirect.The method returns an object of type
PageNode. Later, by setting the corresponding properties of the page node, you can set its name, description, title, creation date, visibility in the navigation, etc.NOTE: You must set the
LinkedNodeIdproperty. You set it to the page node ID of the inner page that you want to redirect to. -
Save the changes.
Save all changes that you have made to the page using theSaveChangesmethod of thePageManager.
EXAMPLE: In the following code example, the
CreateInternalRedirectPagemethod create a new group page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Telerik.Sitefinity.Abstractions;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Pages.Model;
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Pages
{
public partial class PagesSnippets
{
public void CreateInternalRedirectPage(string pageName, Guid redirectionPageId, Guid parentPageNodeId = default(Guid))
{
PageManager manager = PageManager.GetManager();
if (parentPageNodeId == Guid.Empty)
{
parentPageNodeId = SiteInitializer.CurrentFrontendRootNodeId;
}
PageNode parent = manager.GetPageNode(parentPageNodeId);
var pageId = Guid.NewGuid();
PageNode pageNode = manager.CreatePage(parent, pageId, NodeType.InnerRedirect);
pageNode.Name = pageName;
pageNode.Description = pageName;
pageNode.Title = pageName;
pageNode.UrlName = Regex.Replace(pageName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
pageNode.ShowInNavigation = true;
pageNode.DateCreated = DateTime.UtcNow;
pageNode.LastModified = DateTime.UtcNow;
//sets the id of the linked page node
pageNode.LinkedNodeId = redirectionPageId;
manager.SaveChanges();
}
}
}