MvcSiteMapProvider 不适用于简单的 MVC.SiteMap 文件

发布于 2024-10-14 16:59:25 字数 2864 浏览 2 评论 0原文

所以这有点奇怪。我有一个非常简单的站点地图(简化为调试的简单性 - 实时版本要复杂得多):

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="false">
  <mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal">
    <mvcSiteMapNode title="Why Buy Your New Home" Controller="WhyBuyYourNewHome" Action="Index" />
  </mvcSiteMapNode>
</mvcSiteMap>

当我尝试加载页面时,我收到以下错误:

An item with the same key has already been added.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: An item with the same key has already been added.

Source Error:

Line 75:             else
Line 76:             {
Line 77:                 returnValue = UrlHelper.Action(action, controller, new RouteValueDictionary(routeValues));
Line 78:             }
Line 79: 


Source File: C:\sitemap\Branches\3.0.0\MvcSiteMapProvider\MvcSiteMapProvider\DefaultSiteMapNodeUrlResolver.cs    Line: 77 

奇怪的是,如果我删除“为什么购买你的”新家”节点,它有效。另外,以下内容工作得很好,并加载了我的所有动态节点:

    <?xml version="1.0" encoding="utf-8" ?>
    <mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
      <mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal">
        <mvcSiteMapNode title="Find Your New Home" controller="FindYourNewHome" action="Index">
          <mvcSiteMapNode title="Markets" action="Market" updatePriority="Critical" dynamicNodeProvider="MyProject.MVC.Extensions.SiteMap.SiteMapMarketNodeProvider, MyProject.MVC.Extensions">
            <mvcSiteMapNode title="Communities" action="Community" updatePriority="High" dynamicNodeProvider="MyProject.MVC.Extensions.SiteMap.SiteMapCommunityNodeProvider, MyProject.MVC.Extensions">
              <mvcSiteMapNode title="Driving Directions" action="DrivingDirections" updatePriority="High" dynamicNodeProvider="MyProject.MVC.Extensions.SiteMap.SiteMapDrivingDirectionsNodeProvider, MyProject.MVC.Extensions" />
              <mvcSiteMapNode title="Floorplans" action="Floorplan" updatePriority="High" dynamicNodeProvider="MyProject.MVC.Extensions.SiteMap.SiteMapFloorplanNodeProvider, MyProject.MVC.Extensions" />          
            </mvcSiteMapNode>
          </mvcSiteMapNode>
        </mvcSiteMapNode>
      </mvcSiteMapNode>
</mvcSiteMap>

似乎只有当我添加非常简单的节点时,我才会收到此重复键错误,但如果您查看我的第一个 XML 示例,就会发现没有重复的关键可能。如果我将“为什么购买新房”节点添加到包含动态节点提供程序的最后一个 XML 示例中,它会再次中断。对这个有什么帮助吗?

So this is a little strange. I have a VERY simple sitemap (reduced to this simplicity for debugging -- live version is much more complex):

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="false">
  <mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal">
    <mvcSiteMapNode title="Why Buy Your New Home" Controller="WhyBuyYourNewHome" Action="Index" />
  </mvcSiteMapNode>
</mvcSiteMap>

When I try to load the page, I get the following error:

An item with the same key has already been added.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: An item with the same key has already been added.

Source Error:

Line 75:             else
Line 76:             {
Line 77:                 returnValue = UrlHelper.Action(action, controller, new RouteValueDictionary(routeValues));
Line 78:             }
Line 79: 


Source File: C:\sitemap\Branches\3.0.0\MvcSiteMapProvider\MvcSiteMapProvider\DefaultSiteMapNodeUrlResolver.cs    Line: 77 

The strange this is that if I remove the "Why Buy Your New Home" node, it works. Also, the following works just fine and loads all of my dynamic nodes:

    <?xml version="1.0" encoding="utf-8" ?>
    <mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
      <mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal">
        <mvcSiteMapNode title="Find Your New Home" controller="FindYourNewHome" action="Index">
          <mvcSiteMapNode title="Markets" action="Market" updatePriority="Critical" dynamicNodeProvider="MyProject.MVC.Extensions.SiteMap.SiteMapMarketNodeProvider, MyProject.MVC.Extensions">
            <mvcSiteMapNode title="Communities" action="Community" updatePriority="High" dynamicNodeProvider="MyProject.MVC.Extensions.SiteMap.SiteMapCommunityNodeProvider, MyProject.MVC.Extensions">
              <mvcSiteMapNode title="Driving Directions" action="DrivingDirections" updatePriority="High" dynamicNodeProvider="MyProject.MVC.Extensions.SiteMap.SiteMapDrivingDirectionsNodeProvider, MyProject.MVC.Extensions" />
              <mvcSiteMapNode title="Floorplans" action="Floorplan" updatePriority="High" dynamicNodeProvider="MyProject.MVC.Extensions.SiteMap.SiteMapFloorplanNodeProvider, MyProject.MVC.Extensions" />          
            </mvcSiteMapNode>
          </mvcSiteMapNode>
        </mvcSiteMapNode>
      </mvcSiteMapNode>
</mvcSiteMap>

It only seems to be when I add in very simplistic nodes that I'm getting this duplicate key error, yet if you look at my first XML sample, there's no duplicate key possible. If I add that "Why Buy Your New Home" node to my the last XML sample that includes the dynamic node providers, it breaks again. Any help on this one?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

破晓 2024-10-21 16:59:26

这很可能意味着 WhyBuy 节点和其他一些 url 的 URL 是相同的。也许你可以发布你的路线?

This most likely means the URL is the same for that WhyBuy node and some other url. Maybe you could post your routing?

森罗 2024-10-21 16:59:26

因此,最终我在 XML 中将“Controller”和“Action”属性大写了。这导致所有节点都落入我的“包罗万象”的路线,因此从技术上讲,我的所有站点地图节点都匹配单个路线。

咕噜……

So it ended up being the fact that I had capitalized "Controller" and "Action" attributes in the XML. That was causing all nodes to fall to my "catchall" route so technically all of my site map nodes matched a single route.

Grrr....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文