More in this section

Forums / General Discussions / Pages API Find Current Page

Pages API Find Current Page

8 posts, 1 answered
  1. Chris
    Chris avatar
    63 posts
    Registered:
    05 Jan 2011
    24 Jan 2011
    Link to this post
    I've got a support ticket open about this but wanted to see if I could get any feedback from the community.  I have a page called "Support" which apparently conflicts with a page in the Administration area.  I noticed a method for IsBackend() to determine if a page is part of the Admin.  However, when I try to apply it to my LINQ query, it's blowing up.  Here's the code:

    PageManager pManager = PageManager.GetManager();
     
               var pages = pManager.GetPageNodes().Where(pN => pN.UrlName == currentURL && pN.IsBackend == false);
               tmpHolder.Text = "<br /><br />";
               foreach (PageNode page in pages)
               {
     
                   tmpHolder.Text += "<br />BN: " + page.IsBackend.ToString() + " | Title: " + page.Title + " | URL: " + page.UrlName + " | Parent URL: " + page.Parent.UrlName + " | Parent: " + page.Parent.Title + "<br /><br />";
               }

    How can I restructure that query so that I only get the pages where the UrlName matches the currentURL AND it's not part of the Administration area?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Jan 2011
    Link to this post
    Hello Chris,

    Try using this code

    var pgs = App.WorkWith().Pages().Where(p => p.IsBackend == false).Get().ToList();

    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
  3. Chris
    Chris avatar
    63 posts
    Registered:
    05 Jan 2011
    25 Jan 2011
    Link to this post
    Hi Ivan,

    That code is producing the following error:

    Server Error in '/Dev' Application.

    Telerik.Sitefinity.Pages.Model.PageNode, Telerik.Sitefinity.Model was not granted View in Pages for principals with IDs 00000000-0000-0000-0000-000000000000

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: Telerik.Sitefinity.Security.SecurityDemandFailException: Telerik.Sitefinity.Pages.Model.PageNode, Telerik.Sitefinity.Model was not granted View in Pages for principals with IDs 00000000-0000-0000-0000-000000000000

    Source Error:

    Line 38: 
    Line 39:             //var pages = pManager.GetPageNodes().Where(pN => pN.UrlName == currentURL);
    Line 40:             var pages = App.WorkWith().Pages().Where(p => p.IsBackend == false).Get().ToList();
    Line 41:             tmpHolder.Text = "<br /><br />";
    Line 42:             foreach (PageNode page in pages)

    Source File: C:\Program Files (x86)\Telerik\Sitefinity 4.0\Projects\Dev\controls\standardMenu.ascx.cs    Line: 40

    Stack Trace:

    [SecurityDemandFailException: Telerik.Sitefinity.Pages.Model.PageNode, Telerik.Sitefinity.Model was not granted View in Pages for principals with IDs 00000000-0000-0000-0000-000000000000]
       Telerik.Sitefinity.Security.PermissionApplierEnumerator`1.Demand(T forItem) +225
       Telerik.Sitefinity.Security.PermissionApplierEnumeratorBase`1.MoveNext() +112
       System.Linq.WhereEnumerableIterator`1.MoveNext() +148
       System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +472
       System.Linq.Enumerable.ToList(IEnumerable`1 source) +76
       SitefinityWebApp.controls.standardMenu.Page_Load(Object sender, EventArgs e) in C:\Program Files (x86)\Telerik\Sitefinity 4.0\Projects\AccusoftDev\controls\standardMenu.ascx.cs:40
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
       System.Web.UI.Control.LoadRecursive() +95
       System.Web.UI.Control.LoadRecursive() +190
       System.Web.UI.Control.LoadRecursive() +190
       System.Web.UI.Control.LoadRecursive() +190
       System.Web.UI.Control.LoadRecursive() +190
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2760
    


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Jan 2011
    Link to this post
    Hi Chris,

    You get the error, because you are not logged in or the user you use cannot view some of the pages, so you cannot retrieve them using the API.

    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
  5. Chris
    Chris avatar
    63 posts
    Registered:
    05 Jan 2011
    25 Jan 2011
    Link to this post
    Hi Ivan,

    It's a public menu so the user, more times then not, will not be logged in.  How do I look-up the current, non-Administrative page, for everyone?

    Chris
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Jan 2011
    Link to this post
    Hi Chris,

    You can grant Anonymous user to have access over your pages or use PageManager.GetManager().Provider.SuppressSecurityChecks, but it is recommended to consider which users you may grant with the view, edit ,modify etc.

    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. Chris
    Chris avatar
    63 posts
    Registered:
    05 Jan 2011
    25 Jan 2011
    Link to this post
    Hi Ivan,

    Maybe I'm confused but this suppressing the security checks concerns me - can this create a security problem?  All I'm trying to do is determine what page on the front of the site a user is on, based on the current URL.  For example, if they're at mydomain.com/support, I look-up support to determine the page, if they're at mydomain.com/support/knowledgebase, I look-up knowledgebase to determine the page.  My goal is to determine the parent page - in the previous example this is support for both pages.

    The problem is, using the sample code in this thread previously posted in this thread, it's returning both the front support page and the administrative support page.  Since it's a menu widget that appears on the front of the site, I don't want any administrative menus.  I don't really want to fiddle with the security since almost ALL users loading this widget in their template will be public/anonymous users.  Maybe I'm going about this wrong, but how can I determine the current public page I'm on based on the URL ignoring all Admin menus?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Jan 2011
    Link to this post
    Hi Chris,

    You can work with the SiteMapBase class . You can get the current page by using GetActualCurrentNode() method.

    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
    Answered
8 posts, 1 answered