More in this section

Forums / Bugs & Issues / Dynamically created pages content not visible unless logged in as admin

Dynamically created pages content not visible unless logged in as admin

2 posts, 0 answered
  1. Wendy
    Wendy avatar
    4 posts
    Registered:
    28 Jun 2011
    03 Nov 2011
    Link to this post
    I'm creating pages dynamically and adding controls during page creation. The problem I'm experiencing is the page content for these dynamically created pages is not visible UNLESS I'm logged in to Sitefinity. The page template appears but no content. Content for pages created within the UI appears whether logged in or not. Content added via the UI to a dynamically created page will appear.

    There is no value in the sf_control_properties for these dynamically created controls. I didn't see any explicit permissions settings aside from InheritsPermissions for the controls (which didn't help). Viewing the page permissions settings in the UI, the dynamically created pages share the same permissions as the pages created via Sitefinity. Has anyone else run into this problem? Here's the page/control creation code:

                var pageId = Guid.NewGuid();
                var pageDataId = Guid.NewGuid();
                PageManager pageManager = PageManager.GetManager();
                pageManager.Provider.SuppressSecurityChecks = true
                PageData pageData = pageManager.CreatePageData();             pageData.HtmlTitle = pageName;             pageData.Title = pageName;             pageData.Template = pageManager.GetTemplates().Where(t => t.Title.Equals("DynamicLocation")).FirstOrDefault();              pageData.Status = ContentLifecycleStatus.Live;                            PageNode parent = pageManager.GetPageNode(SiteInitializer.FrontendRootNodeId);             PageNode pageNode = pageManager.CreatePage(parent, pageId, NodeType.Standard);             pageNode.Page = pageData;             pageNode.Name = pageName;             pageNode.Title = pageName;             pageNode.UrlName = Regex.Replace(pageUrl.ToLower(), UrlNameCharsToReplace, UrlNameReplaceString);             pageNode.ShowInNavigation = true;             pageNode.DateCreated = DateTime.UtcNow;             pageNode.LastModified = DateTime.UtcNow;             pageManager.RecompileItemUrls<PageNode>(pageNode);
     
                PageNode homePageNode = pageManager.GetPageNodes().Where(n => n.Title.Equals(parentCategory)).FirstOrDefault();
                pageManager.ChangeParent(pageNode, homePageNode);
     
                var draft = pageManager.EditPage(pageData.Id, true);
    
    
                PageDraftControl ctrl1 = pageManager.CreateControl<PageDraftControl>("~/App_widgets/Locations/LocationTitle.ascx""Location Title Content placeholder");
                ctrl1.PlaceHolder = "page_title";
                ctrl1.Caption = "Location Title";
                draft.Controls.Add(ctrl1);
     
                PageDraftControl ctrl2 = pageManager.CreateControl<PageDraftControl>();
                ctrl2.ObjectType = typeof(ContentBlock).FullName;
                ctrl2.PlaceHolder = "middle_content";
                ctrl2.Caption = "Location Description Content Block";
                ctrl2.Description = "Location description";
                draft.Controls.Add(ctrl2);
     
                PageDraftControl ctrl3 = pageManager.CreateControl<PageDraftControl>("~/App_widgets/Services/ServiceList.ascx""Service List Content placeholder");
                ctrl3.PlaceHolder = "services_list";
                ctrl3.Caption = "Service List";
                draft.Controls.Add(ctrl3);
                              pageManager.PublishPageDraft(draft, truenull);             pageManager.SaveChanges();
    Thanks, Wendy
  2. Wendy
    Wendy avatar
    4 posts
    Registered:
    28 Jun 2011
    04 Nov 2011
    Link to this post
    I figured out the issue. I had to add the following to each control:

    ctrl1.SetDefaultPermissions(pageManager);
    

    I'm not sure if this is the best method, i.e. if I was missing an overarching permissions setting somewhere, but this resolved the issue.
2 posts, 0 answered