I am using sharepoint 2010. I try to get the rootnode programmatacilly by this code:

var rootNode = PortalSiteMapProvider.GlobalNavSiteMapProvider.RootNode;

But I got this exception:

  at System.Web.Security.FileAuthorizationModule.IsUserAllowedToFile(HttpContext context, String fileName)
   at System.Web.UI.Util.IsUserAllowedToPath(HttpContext context, VirtualPath virtualPath)
   at System.Web.SiteMapProvider.IsAccessibleToUser(HttpContext context, SiteMapNode node)
   at System.Web.SiteMapProvider.get_RootNode()
   at RocNijmegen.Portaal.WebServices.Navigation.GetGlobalNav()

that error indicates the current user is not a windows authenticated user!

to get around it use:



so it would be somthing like:


private void getnodes()
  var rootNode = PortalSiteMapProvider.GlobalNavSiteMapProvider.RootNode;

When generating navigation elements, the NavigationPortalSiteMapProvider class uses the CachedObject interfaces instead of the actual SPWeb objects. The PortalSiteMapProvider object uses SharePoint Foundation cacheable access control lists (ACLs) to check permissions as necessary, and checks permissions only once per family of PortalSiteMapProvider objects. Any SPWeb object that has the HasUniquePerm property set to false is part of a family. If an object's parent has had its ACL permissions checked and the object shares the same rights as the parent, the current object does not need to be checked because the parent has been checked.



you cant do the method above within a webservice! it needs to be slightly different! as it runs under the current context of the http serivice passing through would fail! you need to pass through the url to the webservice for it to work! the work has been done for you ;)

//method exposed through the web service 
public XmlDocument GetTree(string path) 
    PortalSiteMapProvider psmp = PortalSiteMapProvider.GlobalNavSiteMapProvider; 
    SiteMapNode node = psmp.FindSiteMapNode(path); 
    return BuildXmlFromNode(node); 

private XmlNode BuildXmlFromNode(SiteMapNode node) 
    XmlDocument xml = new XmlDocument(); 
    reutrn BuildXmlFromNode(node, xml); 

//recurses down the sitemapnode children 
private XmlNode BuildXmlFromNode(SiteMapNode node, XmlNode xml) 
    XmlElement element = doc.CreateElement("Node") 
    element.SetAttribute("title", node.Title); 
    element.SetAttribute("url", node.Url); 


    foreach(SiteMapNode childNode in node.ChildNodes) 
        BuildXmlFromNode(childNode, element); 

    return xml; 


  • hi, thanks for your fast support. I have try your code and get another exception: An error occured while rendering navigation for requested URL: /_vti_bin/MyCompanyName/Navigation.asmx. Exception message: Object reference not set to an instance of an object. Stack trace: at Microsoft.SharePoint.Publishing.CacheManager.GetManager(SPSite site, Boolean useContextSite, Boolean allowContextSiteOptimization) at Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider.get_ObjectFactory() at Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider.GetRootNodeCore() – Ola Jan 13 '14 at 14:40
  • is the code within a webservice? – Ali Jafer Jan 13 '14 at 14:53
  • Yes. This code is inside a webservice. – Ola Jan 13 '14 at 15:00
  • just ammended my answer! – Ali Jafer Jan 13 '14 at 15:19
  • I see a method "GetTree". Do I need to give the path of the webapplication where I would like to have the root node? Like "intranet.mycompanyname.com". And I see some code where you get all the childs and generate a xml file. I only want the root node as an "SiteMapNode" object. Is this possible? – Ola Jan 13 '14 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.