SecurityDemandFailException was unhandled by user code
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);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();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();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)".
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
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); 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);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();