問題描述
我正在嘗試使用 SiteMapPath 在我的網站上構建動態站點地圖.
I'm trying to build a dynamic site map on my site using SiteMapPath.
應該是這樣的:
Home > Products > %product_name% > Prices
其中 %product_name%
是在運行時動態設置的,具體取決于用戶的選擇.
where %product_name%
is set dynamically in the runtime, depending on the user's choice.
我已經閱讀了很多關于該主題的文章并選擇了這個http://harriyott.com/2007/03/adding-dynamic-nodes-to-aspnet-site.aspx.它動態更改 web.sitemap
XML 文件.問題是它仍然在開始時只構建站點地圖一次,然后在每個頁面上使用它.
I've read many articles on the theme and choose this http://harriyott.com/2007/03/adding-dynamic-nodes-to-aspnet-site.aspx. It dynamically changes the web.sitemap
XML file. The problem is that it still builds the sitemap only once in the beginning and then uses it on each page.
我怎樣才能讓它在每個加載的頁面上重建?
How can I make it to rebuild on each loaded page?
推薦答案
試試這個:
右鍵單擊您的項目添加新項目",然后選擇站點地圖",它將具有如下所示的 XML 結構:
Right click on your project "add new item" then choose "Site Map", it will have an XML structure that looks like:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/Default.aspx" title="Home " description="">
<siteMapNode url="~/the page URL" title="Products" description="" >
<siteMapNode url="~/the page URL" title=" %product_name%" description="" >
<siteMapNode url="~/the page URL" title="Prices" description="" />
</siteMapNode >
</siteMapNode >
</siteMapNode >
<sitemap>
** 為每個節點添加描述是可選的.
** adding description for each node is optional.
現在你需要把它放在你想要的地方,所以你在頁面的 HTML 端添加這段代碼:
Now you need to place it where you want, so you add this code in the HTML side of the page:
<asp:SiteMapPath ID="SiteMapPath1" runat="server">
<CurrentNodeStyle CssClass="Some class" />
<PathSeparatorTemplate>
<img runat="server" alt="" src="an image to separate between nodes" height="5" width="5" />
</PathSeparatorTemplate>
</asp:SiteMapPath>
<小時>
當然,您有兩頁 - 一頁是產品,一頁是價格.
Of course you have two pages - one for product and one for prices.
為 SiteMap 中的某個節點動態分配 Tile;在價格頁面中添加此代碼:
To assign Tile dynamically for some node in the SiteMap; add this code in the Prices Page:
1) 在頁面加載中:
SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(SiteMap_SiteMapResolve);
2)在同一頁面(價格頁面)添加此功能:
2) Add this function in the same page (prices page):
SiteMapNode SiteMap_SiteMapResolve(object sender, SiteMapResolveEventArgs e)
{
SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
SiteMapNode tempNode = currentNode;
tempNode.ParentNode.Title = "Change the Product name";
tempNode.ParentNode.Url = "Change the Product url";
return currentNode;
}
如您所見,您可以根據需要操作父節點,更改標題、url 等.我認為您也想更改 url;例如:product.aspx?ID=blah"
As you can see you can manipulate the parent Node as you want, change the title, the url, etc. I think you want to change the url too; for example: "product.aspx?ID=blah"
這篇關于在 asp.net 中動態構建的 SiteMapPath的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!