门户站点地图提供者 [英] PortalSiteMapProvider

查看:40
本文介绍了门户站点地图提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我实例化 PortalSiteMapProvider 实例时,它总是默认为根网站集.

Everytime I instantiate a PortalSiteMapProvider instance it always defaults to the Root Web Site Collection.

我希望能够从应用程序页面的不同集合中获取站点地图.

I want to be able to acquire a site map from a different collection from an application page.

因此,上下文默认为根网站,因为此应用程序页面驻留在 _layouts 下并且未托管在任何网站集下.

Because of this, the context defaults to the root web since this application page resides under _layouts and is not hosted under any site collection.

如何从应用程序页面获取除根网站之外的网站集的实例?

How do I acquire an instance to a site collection other than the root web from an application page?

谢谢.

推荐答案

您无法通过 PortalSiteMapProvider 读取其他网站集的层次结构.例如,如果您在网站集 A 中,PSMP 将只遍历 A 的树,而不是 B.您必须在 B 中才能遍历 B.

You can't read another site collection's hierarchy through a PortalSiteMapProvider. E.g., if you are in Site Collection A, PSMP will only traverse A's tree, not B. You have to be in B to traverse B.

我实施的一种解决方法是编写一个简单的 Web 服务,该服务在网站集中运行并将路径作为参数.它读取自己的 PSMP 并从层次结构中的那个点写入 XML 树.从 SC-A 中运行的代码调用位于 SC-B 中的 Web 服务非常快,尤其是因为 PSMP 可以如此快速地破坏 B 的结构.

A workaround I implemented was to write a simple web service that runs in a site collection and takes a path as a parameter. It reads its own PSMP and writes an XML tree from that point in the hierarchy. Calling the web service living in SC-B from code running in SC-A is extremely fast, especially since the PSMP can rip through B's structure so quickly.

以下是在 WSS3/MOSS 中创建 Web 服务的说明.

以下是一些完全非功能性的代码,可帮助您朝着正确的方向前进:

Here is some totally non-functional code to get you headed in the right direction:

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

    xml.AppendChild(element);

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

    return xml;
}

请注意如果您没有设置递归次数限制并且您的站点地图层次结构非常深和/或宽,这可能会产生一个巨大的 xml 文档.谨慎使用!

Please note if you don't set a limit on the number of recursions and your site map hierarchy is very deep and/or wide, this could produce a HUGE xml document. Use with caution!

这篇关于门户站点地图提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆