SecurityDemandFailException was unhandled by user code

Posted by Community Admin on 03-Aug-2018 14:21

SecurityDemandFailException was unhandled by user code

All Replies

Posted by Community Admin on 14-Feb-2011 00:00

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

Posted by Community Admin on 14-Feb-2011 00:00

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

Posted by Community Admin on 14-Feb-2011 00:00

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)".


Posted by Community Admin on 17-Feb-2011 00:00

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

Posted by Community Admin on 17-Feb-2011 00:00

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

        

Posted by Community Admin on 23-Feb-2011 00:00

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

Posted by Community Admin on 23-Feb-2011 00:00

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.

This thread is closed