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

Forums / Developing with Sitefinity / Page details from custom control

Page details from custom control

2 posts, 0 answered
  1. mattc
    mattc avatar
    105 posts
    Registered:
    11 Aug 2007
    18 Nov 2009
    Link to this post
    Hello

    I am trying to get hold of details of the containing CMS page from within a custom control.

    I want the control to be aware if the user is logged in and whether they are the owner of the CMS page that contains the custom control..

    From within the control I can't see how to get an instance of the CMS page..
    Trying things like:
    Guid pageID = ((Telerik.Cms.IPage)(this.Parent.Parent.Page)).ID; 
    var manager = new Telerik.Cms.CmsManager(); 
    Telerik.Cms.IPage page = manager.GetPage(pageID); 
    but my types aren't right..

    Is this the easiest way to get hold of this information?

    Matt
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    18 Nov 2009
    Link to this post
    Hi mattc,

    You can give a try to the code below. It gets the current page and checks for the currently logged user and the name of page owner. If necessary modify the code.

    CmsManager cmsManager = new CmsManager();
    ICmsUrlContext pageID = (ICmsUrlContext)this.Context.Items[Telerik.Cms.Web.UrlHelper.CmsPageKey];
    Guid pID = pageID.PageID;
    ICmsPage page = (ICmsPage)cmsManager.GetPage(pID);
    string loggedUserName = UserManager.GetCurrentUserName();
    if (!String.IsNullOrEmpty(loggedUserName))
    {
        string pOwner = page.Owner;
        if (loggedUserName == pOwner)
        {
            Response.Write("owner and current are the same");
        }
        else
        {
            Response.Write("owner and current are not the same");
        }
    }
     

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered