PortalSiteMapProvider is empty with anonymous access
-
I am trying to use PortalSiteMapProvider to create a tree view Site Map, however, secruity trimming is limiting the results. If you access the page anonymously or with permissions to a grandchild site only, the tree does not build because the provider is empty. I have tried using RunWithElevatedPrivileges with no success. Everything I read about SiteMap providers say the bey default do not use security trimming unless you set the flag to true in the web config. I have verified it is not set. I am open to all suggestions to include a completlydifferent solution for a treeview sitemap. I am including a simple version of the code with the treeview removed.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// Gets a new security context using SHAREPOINT\systemusing (SPSite site = new SPSite(this.Page.Request.Url.ToString())) { using (SPWeb thisWeb = site.OpenWeb()) { PortalSiteMapProvider sitemapprovider = (PortalSiteMapProvider)SiteMap.Providers\["GlobalNavSiteMapProvider"\]; foreach (SiteMapNode node in sitemapprovider.GetChildNodes(sitemapprovider.TryGetRootNode)) { //Use the child node this.Controls.Add(new LiteralControl(node.Title + "<br>")); this.Controls.Add(new LiteralControl(node.Key + "<br>")); this.Controls.Add(new LiteralControl(node.Url + "<br>")); } } }
});