2013-05-08 59 views
0

在我正在使用的SiteMap控件中,我想让2个或更多的节点指向同一页面。多个SiteMap节点具有查询字符串参数相同的URL

<siteMapNode url="~/Default.aspx" title="Home" description="Home page"> 
    <siteMapNode url="~/SectionList.aspx" title="By section" description="List of sections"> 
    <siteMapNode url="~/BrowsePublications.aspx" title="publications of section" description="Publications of section"/> 
    </siteMapNode> 
    <siteMapNode url="~/Officers.aspx" title="By responsible officer" description="List of officers"> 
    <siteMapNode url="~/BrowsePublications.aspx" title="publications of officer" description="Publications of officer"/> 
    </siteMapNode> 
</siteMapNode> 

我基本上有一个网格显示,这个网格可以用很多方式过滤。每个过滤器都是一个页面,用户点击某个条目并被重定向到显示网格的页面,其中包含与该条目相关的数据。我正在使用查询字符串参数来实现。 我在线阅读,要克服这种限制的一种方法是添加虚拟参数或“#”到重复节点的网址的末尾,所以我试图用这个

<siteMapNode url="~/Default.aspx" title="Home" description="Home page"> 
    <siteMapNode url="~/SectionList.aspx" title="By section" description="List of sections"> 
    <siteMapNode url="~/BrowsePublications.aspx?view=2" title="Publication view 1" description="Publication view"/> 
    </siteMapNode> 
    <siteMapNode url="~/Officers.aspx" title="By responsible officer" description="List of officers"> 
    <siteMapNode url="~/BrowsePublications.aspx?view=3" title="Publication view" description="Publication view"/> 
    </siteMapNode> 
</siteMapNode> 

,并使用哈希,但由于我重定向到BrowsePublications.aspx与查询parametrs,(我的网址是一样的东西

BrowsePublications.aspx?鉴于= 2 & C = 24

asp.net不承认它,IG当我尝试访问来自BrowsePublications.aspx的SiteMap.CurrentNode时发生异常。 实现此目的的最简单方法是什么? 谢谢

+0

什么是异常和代码中的哪个位置得到它? – nmat 2013-05-08 17:44:52

+0

的例外是 “对象引用未设置为对象的实例” 我得到它时,我尝试访问SiteMap.CurrentNode内BrowsePublications.aspx.cs 如果我删除这一点,我没有例外,但我的网站地图控制doesn 't render anything – kfc 2013-05-08 17:47:46

+0

see this:http://stackoverflow.com/questions/3113765/sitemap-navigation-and-query-string – nmat 2013-05-08 18:00:06

回答

0

我挣扎了一段时间去做你所问的。在不同的站点地图节点中有一个有效且更简单的方法来使用两个相同的URL(使用不同的查询字符串)。考虑发布解决方案,以便将来任何人都能从中受益。

首先,您需要在站点地图中已经存在父节点和父父节点。

<siteMapNode title="" description="" url="" > 
     <siteMapNode title="ParentParentTest2" description="" url="~/ParentParentTest2.aspx" >  
      <siteMapNode title="ParentTest2" description="" url="~/ParentTest2.aspx" > 
      <siteMapNode title="Page_that_needs_to_be_in_multiple_Nodes" description="" url="~/XYZ.aspx" />   
    </siteMapNode> 
     </siteMapNode> 

     <siteMapNode title="ParentParentTest2" description="" url="~/ParentParentTest2.aspx" > 
      <siteMapNode title="ParentTest2" description="" url="~/ParentTest2.aspx"> 
////you don't have to add the ~/XYZ.aspx node again. If you add it then you will get a multiple node exception. 
      </siteMapNode> 
     </siteMapNode> 

    </siteMapNode> 

//Copy this code in master page Page_Load event 
SiteMap.SiteMapResolve += SiteMap_SiteMapResolve; 

///将此事件处理程序添加到母版页。

public SiteMapNode SiteMap_SiteMapResolve(object sender, SiteMapResolveEventArgs e) 
      { 

       //get current node 
       SiteMapNode currentNode = SiteMap.CurrentNode; 
       if (currentNode != null) 
       { 
        currentNode = SiteMap.CurrentNode.Clone(true); 
        SiteMapNode tempNode = currentNode; 


         SiteMapNode nNewNode = new SiteMapNode(e.Provider,tempNode.Key); 
         switch (tempNode.Key) 
         { 
          case "/Test1.aspx": 
            nNewNode.Clone(true); 

            nNewNode.ParentNode.ParentNode.ReadOnly = false; 
            nNewNode.ParentNode.ReadOnly = false;       
    if(QueryString["Page"]="Test1") 
    {  
            nNewNode.ParentNode.ParentNode = SiteMap.Provider.FindSiteMapNodeFromKey("~/ParentParentTest1.aspx"); 

            nNewNode.ParentNode = SiteMap.Provider.FindSiteMapNodeFromKey("~/ParentTest1.aspx"); 
            nNewNode.ParentNode.ReadOnly = false; 
            nNewNode.ParentNode.Url = "~/ParentTest1.aspx?StateSave=true"; 
            nNewNode.ParentNode.Title = HttpContext.Current.Request.QueryString["ParentNodeName"]; 
            nNewNode.Title = HttpContext.Current.Request.QueryString["CurrentNodeName"]; 
    } 

    if (QueryString["Page"]="Test2") 
    { 
    //Copy the same code and replace Test1 with Test2. 
    } 

    // returning the newly prepared Node.       
          return nNewNode; 
          default: break; 

         } 

        } 

       } 

       return currentNode; 

      } 
相关问题