问题描述
我正在尝试使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!