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

Forums / General Discussions / Create page

Create page

19 posts, 0 answered
  1. Varinder Kumar
    Varinder Kumar avatar
    15 posts
    Registered:
    13 Apr 2010
    13 Aug 2010
    Link to this post
    Hello All,

    I am using Sitefinity 4.0 BETA version and here I am trying to create a page dynamically with the help of http://www.sitefinity.com/40/help/developer-manual/fluent-api-pages-creating-a-page.html.

    But I am getting the following exception:

    Server Error in '/...' Application. You have no permissions to create pages .

    So can anybody suggest me which permissions I need to set for creating page.

    Thanks,
    Varinder Kumar
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Aug 2010
    Link to this post
    Hi Varinder Kumar,

    You could try using SuppressSecurityChecks Property  or give rights for the anonymous users to create pages.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Varinder Kumar
    Varinder Kumar avatar
    15 posts
    Registered:
    13 Apr 2010
    13 Aug 2010
    Link to this post

    Hello Ivan Dimitrov,


    Thanks for reply.

    I implemented the second option (as set rights for the anonymous users to create pages), but now I am getting the following exception:

    You are not authorized to 'View {0}' ('PageTemplates').


    So please suggest me how can I resolve this.

    And one thing, I have not get any help regarding first option (SuppressSecurityChecks Property), it will be very helpful if you also give me some help about this property.

    Thanks,
    Varinder Kumar
  4. Varinder Kumar
    Varinder Kumar avatar
    15 posts
    Registered:
    13 Apr 2010
    13 Aug 2010
    Link to this post
    For this issue, I also tried with Owner/BackendUser checkbox (as checked), but no luck.
  5. Varinder Kumar
    Varinder Kumar avatar
    15 posts
    Registered:
    13 Apr 2010
    13 Aug 2010
    Link to this post
    I am using the following code for creating a page:

    PageManager pManager = new PageManager();
            Guid templateGuid = pManager.GetTemplates().First().Id;
            
            App.WorkWith()
                   .Page()
                   .CreateNewStandardPage(PageLocation.Frontend)
                   .Do(p =>
                   {
                       p.Name = "Page1";
                       p.Title = "This is a test page";
                       p.Description = "Some Description here";
                       p.DateCreated = DateTime.Now; //filled in automatically, but you can control it programatically as well
                       p.UrlName = "page1";          //filled in automatically, but you can set any url name here. 
                       p.ShowInNavigation = true;
                   })
                   .SetTemplateTo(templateGuid)
                   .SaveChanges();
            SiteMapBase.Cache.Flush();
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Aug 2010
    Link to this post
    Hi Varinder Kumar,

    You have to grant view permissions to the user you are using in the same way as you did for "Create'. Please refer to the screenshot that I attached. It would not be possible to create a page if the user is anonymous and you have not granted Create rights.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Varinder Kumar
    Varinder Kumar avatar
    15 posts
    Registered:
    13 Apr 2010
    13 Aug 2010
    Link to this post
    Hello Ivan Dimitrov,

    I really appreciate you help, with using your help I can able to create page dynamically.  

    But I did all the changes in sitefinity environment, it will be great if you suggest me how can I do all the changes (permissions) via code.

    Thanks,
    Varinder Kumar
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Aug 2010
    Link to this post
    Hello Varinder Kumar,

    If the user is anonymous and you have not granted any rights to it form the UI it is not possible to crate a page programmatically. When you are creating a page we demand create permissions in OpenAccessPageProvider. With pages, permissions depend on the parent node - FrontEndNode rather than the security root. When you create a page with anonymous user pages permission set returns that you do not have rights. Generally SuppressSecurityChecks Property   should work in this case, but we found a small glitch with OpenAccessPageProvider and its ChangeParent method. I believe that we will be able to come up with a solution about this issue before the official release. Currently I am not able to give you another option.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Lino
    Lino avatar
    45 posts
    Registered:
    06 May 2005
    13 Aug 2010
    Link to this post
    Hi Ivan and Team,

    Isn't there a way to login programmatically as admin for example and get a token back to use during a period of time to be able to do this instead of requiring anonymous access creation permission or suppress anything?
    It would be nice to know that if I am maintaining a dozen SF 4.0 sites for customers and want to use same code to do maintenance on site, I only need a login username and password to add to my login code and we are good to go.

    This issue will come again when we discuss WCF REST Services. There has to be away to make these REST calls succeed without interaction with setting permissions visually on the admin site temporarily

    What do you think?

    Cheers
    Lino
  10. Varinder Kumar
    Varinder Kumar avatar
    15 posts
    Registered:
    13 Apr 2010
    13 Aug 2010
    Link to this post
    Hello Ivan Dimitrov.

    Thanks again for your reply,

    I can now create a page, but I am seeing the status as Draft, so for publish the page, I am using the following code: 

    1.        var page = pManager.GetPageDataList().Where(t => t.Id == pageID).SingleOrDefault();
    2.        PageDraft editPage = pManager.EditPage(page.Id, false);
            
    3.        //Publish the draft page, and save the changes to the page. 
    4.        pManager.PublishPageDraft(editPage.Id, true);
    5.        pManager.SaveChanges();

    but I am getting the exception on 4th line as below:

    Server Error in '/...' Application.

    Unauthenticated request. Most likely your session has expired. Please login and try again.


    Can you please suggest me where I am wrong or how we can publish the newly created page by dynamically.

    Thanks,
    Varinder  Kumar
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Aug 2010
    Link to this post
    Hi Varinder Kumar,

    Try using the code below to publish the page

    var d = manager.GetPageNodes().Where(t => t.Title == "c").FirstOrDefault();
    if (d != null)
    {
        PageNode node = manager.GetPageNode(new Guid(d.Page.Id.ToString()));
        var draft = manager.GetDraft<PageDraft>(node.Page.Drafts[0].Id);
        manager.PublishPageDraft(draft, true);        
        manager.SaveChanges();
     
    }

    Make sure that the current user has been authenticated or anonymous users have Edit, Modify permissions.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. Lupi
    Lupi avatar
    38 posts
    Registered:
    17 May 2004
    25 Aug 2010
    Link to this post
    Hello,

    Have you tested the code above? When I create a page and .SaveChanges() and .Cache.Flush() I get its PageNode with the code above, but the node.Page.Drafts collection is empty, thus node.Page.Drafts[0].ID throws an exception. I see that for the newly created page there is one record in the sf_page_data and one record in the sf_page_node tables, but I can't get a references to its Draft in any way.

    Lupi
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    25 Aug 2010
    Link to this post
    Hello Lupi,

    Have you created a Draft for your page by calling SavePageDraft method ?

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. Lupi
    Lupi avatar
    38 posts
    Registered:
    17 May 2004
    25 Aug 2010
    Link to this post
    Hey there,

    I couldn't find a way to save a draft but I found that setting both these properties

    pageData.Status = ContentLifecycleStatus.Live;
    pageData.UIStatus = ContentUIStatus.Published;

    makes the page "Published". I guess the exhaustion made me overlook this combination :)

    Lupi
  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 Aug 2010
    Link to this post
    Hello Lupi,

    Here is a sample that shows how to create draft and publish it.

    // crate a draft
    var d = manager.GetPageNodes().Where(t => t.Title == "c").FirstOrDefault();
    if (d != null)
     {
         PageNode node = manager.GetPageNode(new Guid(d.Page.Id.ToString()));
         var pageDraft = manager.EditPage(node.Page.Id, false);
         manager.SavePageDraft(pageDraft.Id);
     }
     
     
    // publish the draft later
    var draft = manager.GetDraft<PageDraft>(node.Page.Drafts[0].Id);
    var pageId = draft.ParentPage.Id;
    manager.PublishPageDraft(draft, true);


    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  16. Lupi
    Lupi avatar
    38 posts
    Registered:
    17 May 2004
    26 Aug 2010
    Link to this post
    Hello,

    Thanks for the code. It works, except for this line

    manager.PublishPageDraft(draft, true);

    It throws an exception saying Unauthenticated request. Most likely your session has expired. Please login and try again. I have given rights to Anonymous users to Edit page content, Create a page and Modify a page, so they should have enough rights.

    Anyway, I don't need to use PageDrafts now. I'm having another issue now - I'm trying to add a ContentBlock to a PageData.Controls collection, but I can't find a way. Here's my code:

    Guid tempGuid = new Guid(thisGuidExistsForSure);
    ContentItem genericContentItem = contentManager.GetItems<ContentItem>().Where(t => t.Id == tempGuid).FirstOrDefault();
    if (genericContentItem != null)
    {
        PageControl pageControl = m_PageManager.CreateControl<PageControl>(genericContentItem, containerId);
        pageData.Controls.Add(pageControl);
    }

    Here the PageManager.CreateControl cannot accept Telerik.Sitefinity.GenericContent.Model.ContentItem as its first parameter. I'm currently pulling the text from the ContentItem's Content property and create a Telerik.Sitefinity.Modules.GenericContent.Web.UI.ContentBlock with this text, but if I change the contents of the ContentItem the changes won't be reflected in the page where I use this text.

    Some code snippet how to do it would be highly appreciated.
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 Aug 2010
    Link to this post
    Hello Lupi,

    Try using this code


    var mgr = PageManager.GetManager();
     var pg = mgr.GetPageNodes().Where(t => t.Title == "pagetitle").FirstOrDefault();
     var cntrl = new ContentBlock();
     var cn =  cntrl as Control;
     // you can get container id from controls collection
     var pageCtrl = mgr.CreateControl<PageControl>(cn, "11468307001_Col00");
     pg.Page.Controls.Add(pageCtrl);
     mgr.SaveChanges();


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  18. Lupi
    Lupi avatar
    38 posts
    Registered:
    17 May 2004
    26 Aug 2010
    Link to this post
    Hello,

    This is not what I need. Your code downcasts ContentBlock to System.Web.UI.Control then adds it to the Page Controls collection. This I already do. What I need is to add Telerik.Sitefinity.GenericContent.Model.ContentItem, which represents a Generic content item added in the admin -> Content -> Generic content. ContentItem does not inherit from System.Web.UI.Control, so is it possible to add such instance to a Page or PageTemplate. I have the name of the container that will hold the ContentItem.

    Regards,
    Lupi
  19. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 Aug 2010
    Link to this post
    Hello Lupi,

    1. There is no overload of CreateControl that adds ContentItem or any content object

    2. You can add widgets on a page.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
19 posts, 0 answered