2013-10-22 85 views
1

我正在使用SiteMapPath來顯示菜單。ASP.Net - 在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="" /> 

但該項目不顯示。有沒有可能在網站地圖中鏈接網站?

+0

你知道爲什麼它不是desplaying? 如果您將directurl作爲url值,則它會將其視爲頁面名稱,並將在項目目錄中查找頁面。 – Jay

回答

1

我認爲後可能包含您的問題的解決方案:Referencing external URLs in your web.sitemap in ASP.NET

編輯:由於該網站www.sciosoft.com不再響應,這裏是從http://web.archive.org/web/20170821015820/http://www.sciosoft.com:80/blogs/post/2010/02/23/Referencing-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對我們要完成的任務不太清楚,這對下一個在該網站上工作的人來說永遠不會有好處,但是選擇是你的。

+0

謝謝...我知道了..我正在使用基於角色的安全性 – Sobhan