Create page

Posted by Community Admin on 03-Aug-2018 12:08

Create page

All Replies

Posted by Community Admin on 13-Aug-2010 00:00

Hello All,

I am using Sitefinity 4.0 BETA version and here I am trying to create a page dynamically with the help of www.sitefinity.com/.../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

Posted by Community Admin on 13-Aug-2010 00:00

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

Posted by Community Admin on 13-Aug-2010 00:00

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

Posted by Community Admin on 13-Aug-2010 00:00

For this issue, I also tried with Owner/BackendUser checkbox (as checked), but no luck.

Posted by Community Admin on 13-Aug-2010 00:00

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

Posted by Community Admin on 13-Aug-2010 00:00

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

Posted by Community Admin on 13-Aug-2010 00:00

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

Posted by Community Admin on 13-Aug-2010 00:00

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

Posted by Community Admin on 13-Aug-2010 00:00

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

Posted by Community Admin on 13-Aug-2010 00:00

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

Posted by Community Admin on 16-Aug-2010 00:00

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

Posted by Community Admin on 25-Aug-2010 00:00

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

Posted by Community Admin on 25-Aug-2010 00:00

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

Posted by Community Admin on 25-Aug-2010 00:00

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

Posted by Community Admin on 26-Aug-2010 00:00

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

Posted by Community Admin on 26-Aug-2010 00:00

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.

Posted by Community Admin on 26-Aug-2010 00:00

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

Posted by Community Admin on 26-Aug-2010 00:00

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

Posted by Community Admin on 26-Aug-2010 00:00

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

This thread is closed