More in this section

Forums / General Discussions / SecurityDemandFailException was unhandled by user code

SecurityDemandFailException was unhandled by user code

7 posts, 0 answered
  1. Chris
    Chris avatar
    63 posts
    Registered:
    05 Jan 2011
    14 Feb 2011
    Link to this post
    Trying to execute this code:

    IQueryable<PageNode> pageNodes = App.WorkWith()
    .Pages()
    .Where(pN => pN.Page.Status == ContentLifecycleStatus.Live)
    .Where(pN => pN.Page.IsBackendPage == false)
    .Get();
     
    foreach (PageNode pageNode in pageNodes)
    {
    Response.Write("<br />");
    Response.Write(pageNode.Title);
    }

    throws this error:

    Telerik.Sitefinity.Pages.Model.PageNode, Telerik.Sitefinity.Model was not granted View in Pages for principals with IDs 00000000-0000-0000-0000-000000000000
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    14 Feb 2011
    Link to this post
    Hello Chris,

    It looks like you have a page which is restricted for anonymous users and you get the exception when you try to work with the page. Can you please try with this query first:
    IQueryable<PageNode> pageNodes
        = App.WorkWith()
            .Pages()
            //get front end pages
            .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
            .Where(pN => pN.Page.Status == ContentLifecycleStatus.Live)
            .Get();

    If this query does not work you can suppress security checks:
    var fluent = App.WorkWith();
    fluent.Pages().GetManager().Provider.SuppressSecurityChecks = true;
    IQueryable<PageNode> pageNodes =
        fluent.Pages()
            .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
            .Where(pN => pN.Page.Status == ContentLifecycleStatus.Live)
            .Get();


    Regards,
    Radoslav Georgiev
    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
    14 Feb 2011
    Link to this post
    Hi Radoslav,

    Thank you for the response.  I tried both sets of code and now I'm getting a "NullReferenceException was unhandled by user code" on the line ".Where(pN => pN.Page.Status == ContentLifecycleStatus.Live)".


  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    17 Feb 2011
    Link to this post
    Hi Chris,

    Can you please make sure that you have published pages on the front end? Also please show us your complete code.

    Regards,
    Radoslav Georgiev
    the Telerik team
  5. Chris
    Chris avatar
    63 posts
    Registered:
    05 Jan 2011
    17 Feb 2011
    Link to this post
    Hi Radoslav,

    Yes, I have 4 published, working pages on the front of the site.  Here's the entire function in my 404 page:


    protected void Page_Load(object sender, EventArgs e)
            {
                string from = Request.QueryString["aspxerrorpath"];
                int index = from.LastIndexOf("/") + 1;
                string search = from.Substring(index);
     
                var fluent = App.WorkWith();
                fluent.Pages().GetManager().Provider.SuppressSecurityChecks = true;
                IQueryable<PageNode> pageNodes = fluent.Pages()
                    //get front end pages
                    .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                    .Where(pN => pN.Page.Status == ContentLifecycleStatus.Live)
                    .Get();
     

     
                foreach (PageNode pageNode in pageNodes)
                {
                    Response.Write("<br />");
                    Response.Write(pageNode.Title);
                    Response.Write("|");
                    Response.Write(pageNode.Id);
                    Response.Write("|");
                    Response.Write(pageNode.Owner);
                }
     

            }
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    23 Feb 2011
    Link to this post
    Hi Chris,

    Can you please verify that this is the same exception? If for example you have a group page its Page property will be null:
    var fluent = App.WorkWith();
    fluent.Pages().GetManager().Provider.SuppressSecurityChecks = true;
    IQueryable<PageNode> pageNodes = fluent.Pages()
        //get front end pages
        .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
        .Where(p=> p.Page != null)
        .Where(p=> p.Page.Status == ContentLifecycleStatus.Live)
        .Get();
     
    foreach (PageNode pageNode in pageNodes)
    {
        Response.Write("<br />");
        Response.Write(pageNode.Title);
        Response.Write("|");
        Response.Write(pageNode.Id);
        Response.Write("|");
        Response.Write(pageNode.Owner);
    }


    Best wishes,
    Radoslav Georgiev
    the Telerik team
  7. Chris
    Chris avatar
    63 posts
    Registered:
    05 Jan 2011
    23 Feb 2011
    Link to this post
    Hi Radoslav,

    They are all physical pages, not group pages.  I fixed it using the following code:

    // Return all published, front facing, available in navigation pages
                    var fluent = App.WorkWith();
                    fluent.Pages().GetManager().Provider.SuppressSecurityChecks = true;
                    IQueryable<PageNode> pageNodes = fluent.Pages()
                        .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                        .ThatArePublished()
                        .Where(pN => pN.ShowInNavigation == true)
                        .Get();

    The "ThatArePublished()" and "Where(pN => pN.ShowInNavigation == true)" ensure they are user created pages so I don't receive that error anymore.
7 posts, 0 answered