如果发布站点集合已经管理或结构导航设置为顶部导航的源,您如何以编程方式使用这些设置? SPWeb.Navigation.TopNavigationBar 属性完全返回不同的导航节点(非发布站点上的顶部链路栏)。

这里是我谈论的设置的一些UI屏幕截图:

not-publishing(顶部链接栏设置):

发布(全局导航设置):

如何以编程方式检测站点是否使用全球导航/顶部导航设置的SPNavigation.TopNavigationBar,托管导航或结构导航?

有帮助吗?

解决方案

Alright, so after peering into the inner workings of the code behind for those settings pages, I've found that you can detect the source of the publishing site's navigation by using the WebNavigationSettings class and reading its GlobalNavigation.Source property (a StandardNavigationSource enum) like such:

if (PublishingWeb.IsPublishingWeb(web))
{
    WebNavigationSettings settings = new WebNavigationSettings(web);
    switch (settings.GlobalNavigation.Source)
    {
        case StandardNavigationSource.PortalProvider:
            // Data source is Structured Navigation
            break;
        case StandardNavigationSource.TaxonomyProvider:
            // Data source is Managed Navigation
            break;
        case StandardNavigationSource.InheritFromParentWeb:
            // Root navigation data source is inherited
            break;
        case StandardNavigationSource.Unknown:
            // The documentation for this value states:
            // "Returns a value of unknown to indicate an advanced configuration
            // that does not correspond to one of the standard configurations.
            // This value cannot be manually assigned to the Source property."
            break;
    }
}
else
{
    // Non-publishing site, root source is SPNavigation.TopNavigationBar
}
许可以下: CC-BY-SA归因
scroll top