动态建立的SiteMapPath在asp.net [英] Dynamically built SiteMapPath in asp.net

查看:356
本文介绍了动态建立的SiteMapPath在asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立使用的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端添加此code:

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.

要在地图的某个节点动态分配瓷砖;在价格页面添加此code:

To assign Tile dynamically for some node in the SiteMap; add this code in the Prices Page:

1)在页面加载速度:

1) In the page load:

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 =胡说?

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"

这篇关于动态建立的SiteMapPath在asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆