我有一个问题类似的一个描述这里:
ASP.NET URL路由与web表单的使用的网站地图

我ASP.Net web表单web有一个网站地图,类似于这样的:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode title="Root">
    <siteMapNode url="Home" title="Home" />
      <siteMapNode url="Home?" title="Home" />
      <siteMapNode url="Faq" title="FAQ" />
    </siteMapNode>
    <siteMapNode url="Reports" title="Your reports" />
      <siteMapNode url="Reports?" title="Your reports" />
      <siteMapNode url="ExtraReports" title="Extra reports" />
    </siteMapNode>
    <siteMapNode url="Presentations" title="Your presentations" />
      <siteMapNode url="Presentations?" title="Your presentations" />
      <siteMapNode url="ExtraPresentations" title="Extra presentations" />
    </siteMapNode>
 </siteMapNode>

我想有在以下格式:
://host/项目/{公司}/{projectno}/家庭
://host/项目/微软/10/家庭
://host/项目/微软/11/报告
://host/项目/苹果/10/ExtraReports

Url路路线/项目/{公司}/{projectno}/{pagename}至/Pages/{pagename}.aspx。

我的航行包括一TabStrip上,它应包含 家报告和介绍 和一个菜单上留下他们的子项(例如与家庭选择应该是: 家庭、常见问题).

我的问题:

  1. 什么是适当的方式来处理的重复SiteMapNode url?

  2. 我如何防止TabStrip从中产生的网址如:://host/家://host/ExtraReports?
    我需要保持目前的公司和projectno选择,并且该网站地图忽略相对的网址

  3. 该TabStrip和菜单控制需要认识到所选择的项目显示的活动的选择。什么是适当解决这一切吗?

有帮助吗?

解决方案

在花费几个小时关于这一点,我认为我已经来到一个很好的(够了:))的解决方案。

网站的文件
通知的节点,而不url将指向父母

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
    <siteMapNode>
        <siteMapNode title="Home" url="Home">
            <siteMapNode title="Home" />
            <siteMapNode title="xxx" url="Cycle"/>
            <siteMapNode title="yyy" url="Survey" />
            <siteMapNode title="zzzteam" url="Team" />
        </siteMapNode>
        ...

工具类产生的Url
CurrentContext是一个静态的参照RequestContext

public static string GetPageUrl(SiteMapNode node) {
   RouteValueDictionary values = new RouteValueDictionary(CurrentContext.RouteData.DataTokens);
   values["page"] = node.Url.Trim('/');

   return CurrentContext.RouteData.Route.GetVirtualPath(CurrentContext, values).VirtualPath;
}

数据绑定的活动在提供
导航的是一个阶段Tabstrip,子是的ASP.Net 菜单

private void navigation_TabDataBound(object sender, Telerik.Web.UI.RadTabStripEventArgs e) {
   if (!String.IsNullOrEmpty(e.Tab.NavigateUrl)) {              
          SiteMapNode node = (SiteMapNode) e.Tab.DataItem;

   // Is this tab a parent of the current navigation node? Then select it
   if (SiteMap.CurrentNode.IsDescendantOf(node)) e.Tab.Selected = true;
          e.Tab.NavigateUrl = XRouteHandler.GetPageUrl(node);
   }
}

private void subNavigation_MenuItemDataBound(object sender, MenuEventArgs e) {
    SiteMapNode itemNode = (SiteMapNode) e.Item.DataItem;
    SiteMapNode currentNode = SiteMap.CurrentNode;

    // SiteMapNodes without url will point to the parent node
    if (String.IsNullOrEmpty(itemNode.Url)) {
        itemNode = itemNode.ParentNode;
        e.Item.Selectable = true;
    }

    // Is this menu item the node itself or one of it's parents? Then select it
    if (currentNode == itemNode || currentNode.IsDescendantOf(itemNode))
        e.Item.Selected = true;
        e.Item.NavigateUrl = XRouteHandler.GetPageUrl(itemNode);
    }
}

XmlSiteMapProvider执行情况
这种解决方案是不够好,现在,看看它后来美化了:)

public override SiteMapNode FindSiteMapNode(HttpContext context) {
        string pageName = context.Request.Url.Segments.Last().Trim('/');
        foreach (SiteMapNode node in SiteMap.RootNode.GetAllNodes())
                if (node.Url.EndsWith(pageName, StringComparison.InvariantCultureIgnoreCase)) return node;
        return SiteMap.RootNode;
}

其他提示

Zyphax,

它是最有可能,你将不得不重新写入TabStrip和菜单的控制,以考虑到你的路线。这还将意味着你可以删除重复的SiteMapNodes.

而你会需要编写一些代码穿越树地图,以获得最远的祖先这是一个孩子的家庭网页。这是一个扩展方法,它可能会有帮助。

public SiteMapNode FurthestAncestor(this SiteMapNode node)
{
    while (node.Key !=  this.RootNode.Key && node.ParentNode.Key != this.RootNode.Key)
    {
        node = node.ParentNode;
    }

    return node;
}

还使用相对的网址将帮助 ../演示文稿 而不是 /项目/苹果/10/演示文稿

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top