在asp.net中动态构建SiteMapPath

GaG*_*r1n 4 sitemap navigation asp.net sitemappath

我正在尝试使用SiteMapPath在我的网站上构建动态站点地图.

应该是这样的:

Home > Products > %product_name% > Prices
Run Code Online (Sandbox Code Playgroud)

where %product_name%在运行时动态设置,具体取决于用户的选择.

我已经阅读了很多关于这个主题的文章,并选择了这个http://harriyott.com/2007/03/adding-dynamic-nodes-to-aspnet-site.aspx.它动态更改web.sitemapXML文件.问题是它仍然只在开始时构建一次站点地图,然后在每个页面上使用它.

如何在每个加载的页面上重建它?

Arr*_*abi 7

试试这个:

右键单击您的项目"添加新项目",然后选择"站点地图",它将具有如下所示的XML结构:

<?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>
Run Code Online (Sandbox Code Playgroud)

**为每个节点添加说明是可选的.

现在您需要将它放在您想要的位置,因此您可以在页面的HTML端添加此代码:

<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>
Run Code Online (Sandbox Code Playgroud)

当然你有两页 - 一个是产品,另一个是价格.

为SiteMap中的某个节点动态分配Tile; 在价格页面中添加此代码:

1)在页面加载中:

SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(SiteMap_SiteMapResolve);
Run Code Online (Sandbox Code Playgroud)

2)在同一页面(价格页面)添加此功能:

 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;
}
Run Code Online (Sandbox Code Playgroud)

如您所见,您可以根据需要操作父节点,更改标题,网址等.我认为您也想更改网址; 例如:"product.aspx?ID = blah"