2

我正在使用 SiteMapPath 来显示菜单。

<?xml version="1.0" encoding="utf-8" ?>
<siteMapNode url="default.aspx" title="Home"  description="Sitemap example's home page">
  <siteMapNode url="products.aspx" title="Products"  description="Products listing page">
    <siteMapNode url="products/product1.aspx" title="Product 1"  description="" />
    <siteMapNode url="products/product2.aspx" title="Product 2"  description="" />        
  </siteMapNode>
  <siteMapNode url="services.aspx" title="Services"  description="Services listing page" >
    <siteMapNode url="services/service1.aspx" title="Services 1"  description="" />
    <siteMapNode url="services/service2.aspx" title="Services 2"  description="" />
  </siteMapNode>
</siteMapNode>

我想在我的菜单中链接另一个网站,例如

<siteMapNode url="http://www.google.com" title="Google"  description="" />  

但该项目未显示。是否可以在站点地图中链接网站?

4

1 回答 1

2

我认为该帖子可能包含您的问题的解决方案:Referencing external URLs in your web.sitemap in ASP.NET

编辑:由于网站 www.sciosoft.com 不再响应,这是从http://web.archive.org/web/20170821015820/http://www.sciosoft.com复制的博客文本(由 James Fielding 撰写) :80/blogs/post/2010/02/23/Reference-external-URLs-in-your-websitemap-in-ASPNET.aspx

在 ASP.NET 中,我们经常使用站点地图来设置导航,尤其是菜单。默认情况下,ASP.NET 站点地图提供程序使用“Web.sitemap”文件。下面是一个简单站点的文件示例:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
    <siteMapNode title="Home" description="Home" url="~/default.aspx">
        <siteMapNode title="Services" description="Services we offer" url="~/Services.aspx">
            <siteMapNode title="Consulting" description="Consulting services" url="~/Consulting.aspx" />
            <siteMapNode title="Support" description="Supports plans" url="~/Support.aspx" />
        </siteMapNode>
        <siteMapNode title="About Us" description="About Us" url="~/AboutUs.aspx">
            <siteMapNode title="Company" description="Our people and offices" url="~/Company.aspx" />
            <siteMapNode title="Blogs" description="Blogs from us to you"
              url="http://blogs.mysite.com/default.aspx" />
        </siteMapNode>
    </siteMapNode>
</siteMap>

所以我们的基本菜单将如下所示:

首页 服务 咨询 支持 关于我们 公司博客

请注意,“关于我们”部分中的“博客”节点引用了外部 URL。这不是问题,直到您开始向站点添加基于角色的安全性。具体来说,一旦您在 Web.config 或 Web.sitemap 文件中设置了 securityTrimmingEnabled="true",“博客”节点就会消失,而您只能摸不着头脑。

首页 服务 咨询 支持 关于我们 公司

此时,您会发现一些开发人员摆脱了 web.sitemap,并开始对菜单项进行硬编码。但是,这种行为有一个非常简单的解决方法。只允许每个人访问博客节点,这样它就不会被修剪:

<siteMapNode title="Blogs" description="Blogs from us to you"
    url="http://blogs.mysite.com/default.aspx" roles="*">

通过添加角色=“*”,我们恢复了我们的博客。那简直太容易了。

为了完整起见,我要提一下,我们也可以通过将 securityTrimmingEnabled="false" 添加到博客节点来禁用 Web.sitemap 文件中的安全修整。尽管我不是这种方法的忠实拥护者,因为我发现它使 Web.sitemap 不太清楚我们要完成的工作,这对下一个在网站上工作的人来说从来都不是好事,但选择权在你.

于 2013-10-22T06:17:44.240 回答