Menu 一个站点地图具有相同url的多个站点地图节点
我在这里遇到了一些令人沮丧和困惑的情况。所以,让我详细解释一下。 对于菜单: 我有一个绑定到站点地图的水平菜单(目前不关心站点地图)。单击所有菜单项时,会将用户指向一个页面,即~/Categories.aspx和一个查询字符串。我有一个onMenuItemClick事件,如下所示:Menu 一个站点地图具有相同url的多个站点地图节点,menu,sitemap,Menu,Sitemap,我在这里遇到了一些令人沮丧和困惑的情况。所以,让我详细解释一下。 对于菜单: 我有一个绑定到站点地图的水平菜单(目前不关心站点地图)。单击所有菜单项时,会将用户指向一个页面,即~/Categories.aspx和一个查询字符串。我有一个onMenuItemClick事件,如下所示: protected void myMenu_MenuItemClick(object sender, MenuEventArgs e) { // this is the menu itself, you ca
protected void myMenu_MenuItemClick(object sender, MenuEventArgs e)
{
// this is the menu itself, you can iterate the Items collection if you need.
var menu = (sender as Menu);
foreach (MenuItem item in menu.Items)
{
System.Diagnostics.Debug.Print(item.Text);
}
// this is the MenuItem object that was clicked
var clickedMenuItem = e.Item;
// store text value in your session
Session["1"] = e.Item.Text;
// redirect
Response.Redirect("~/CategorySearch.aspx?Category=" + e.Item.Text);
}
当我手动填充菜单项时,上面的代码工作正常。现在我想将站点地图绑定到我的菜单,我的问题是所有菜单项都有相同的URL,这会引发异常,因为URL必须是唯一的
这是我的网站地图:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode title="DummyRoot">
<siteMapNode url="~/Home.aspx" title="Home" />
<siteMapNode url="~/Category.aspx" title="Track Events">
<siteMapNode url="~/Category.aspx" title="Athletics" />
<siteMapNode url="~/Category.aspx" title="Cycling" />
<siteMapNode url="~/Category.aspx" title="Equestrian Sports" />
<siteMapNode url="~/Category.aspx" title="Motor Sports" />
<siteMapNode url="~/Category.aspx" title="Marathon" />
</siteMapNode>
<siteMapNode url="~/Category.aspx" title="Court Events">
<siteMapNode url="~/Category.aspx" title="Volleyball" />
<siteMapNode url="~/Category.aspx" title="Tennis" />
<siteMapNode url="~/Category.aspx" title="Squash" />
</siteMapNode>
<siteMapNode url="~/Category.aspx" title="Field Events">
<siteMapNode url="~/Category.aspx" title="Archery" />
<siteMapNode url="~/Category.aspx" title="Football" />
<siteMapNode url="~/Category.aspx" title="Cricket" />
</siteMapNode>
</siteMapNode>
我有什么办法让事情顺利进行?要有一个有效的站点地图文件,不能有两个具有相同Url的节点 在您的例子中,您有动态内容,因此在编译时不知道所有节点。因此,要解决您的问题,您需要在运行时更改站点地图的节点。您可以在此处看到一个可能的解决方案: 不要忘记为每个菜单项编写完整的Url。例:
<siteMapNode url="~/CategorySearch.aspx" title="Track Events">
<siteMapNode url="~/CategorySearch.aspx?Category=Athletics" title="Athletics" />
</siteMapNode>