1

嗨,我在母版页中有一个站点地图。我需要将查询字符串动态传递给我的站点地图。有没有人有这方面的经验。这是我的代码

网站地图

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="" title="Employee Benefit"  description="">

        <siteMapNode url="~/Module/EB/Company/CompanyList.aspx" title="Company list"  description="Company List" >
            <siteMapNode url="~/Module/EB/Company/CompanyDetail.aspx" title="Company Detail"  description="Company Detail" >
                <siteMapNode url="~/Module/EB/Employee/EmployeeDetail.aspx" title="Employee Detail"  description="Employee Detail" />
            </siteMapNode>
        </siteMapNode>

    </siteMapNode>
</siteMap>

大师.aspx

<asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Microsoft New Tai Lue" 
    Font-Size="0.9em" PathSeparator=" : " SkipLinkText="" Font-Bold="False" 
    style="font-family: 'Times New Roman', Times, serif; font-size: small" 
    Visible="True" >
        <CurrentNodeStyle ForeColor="#333333" />
        <NodeStyle Font-Bold="True" ForeColor="#284E98" />
        <PathSeparatorStyle Font-Bold="True" ForeColor="#507CD1" />
        <RootNodeStyle Font-Bold="True" ForeColor="#507CD1" />
</asp:SiteMapPath>

顺便一提。我的站点地图可能有多个子站点地图节点。例如

 companylist -> companydetail -> EmployeeDetail->.....

如何将查询字符串传递给其他子 sitemapNope ?

companylist -> companydetail?subID=1 -> EmployeeDetail?subID=2 ->....
4

1 回答 1

0

代码隐藏:

   protected string CustomersURL
    {
        get 
        {
            System.Text.StringBuilder url = new System.Text.StringBuilder("~/Module/EB/Company/CompanyList.aspx");
            if (condition)
            {
                url.AppendFormat(@"?param1={0}", someparameter);
            }
            return url.ToString(); 
        }
    }

.ASPX:

    <siteMapNode url='<%# CustomersURL %> title="Company list"  description="Company List" >

编辑 :

查看 MSDN 的以下解释,它可以很好地解决您的问题:

http://msdn.microsoft.com/en-us/library/ms178425%28v=vs.100%29.aspx

private void Page_Load(object sender, EventArgs e)
{
    // The ExpandForumPaths method is called to handle
    // the SiteMapResolve event.
    SiteMap.SiteMapResolve +=
      new SiteMapResolveEventHandler(this.ExpandForumPaths);
}

private SiteMapNode ExpandForumPaths(Object sender, SiteMapResolveEventArgs e)
{
    // The current node represents a Post page in a bulletin board forum.
    // Clone the current node and all of its relevant parents. This
    // returns a site map node that a developer can then
    // walk, modifying each node.Url property in turn.
    // Since the cloned nodes are separate from the underlying
    // site navigation structure, the fixups that are made do not
    // effect the overall site navigation structure.
    SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
    SiteMapNode tempNode = currentNode;

    // Obtain the recent IDs.
    int forumGroupID = GetMostRecentForumGroupID();
    int forumID = GetMostRecentForumID(forumGroupID);
    int postID = GetMostRecentPostID(forumID);

    // The current node, and its parents, can be modified to include
    // dynamic querystring information relevant to the currently
    // executing request.
    if (0 != postID)
    {
        tempNode.Url = tempNode.Url + "?PostID=" + postID.ToString();
    }

    if ((null != (tempNode = tempNode.ParentNode)) &&
        (0 != forumID))
    {
        tempNode.Url = tempNode.Url + "?ForumID=" + forumID.ToString();
    }

    if ((null != (tempNode = tempNode.ParentNode)) &&
        (0 != forumGroupID))
    {
        tempNode.Url = tempNode.Url + "?ForumGroupID=" + forumGroupID.ToString();
    }

    return currentNode;
}


...


// These methods are just placeholders for the example.
// One option is to use the HttpContext or e.Context object
// to obtain the ID.
private int GetMostRecentForumGroupID()
{
    return 24;
}

private int GetMostRecentForumID(int forumGroupId)
{
    return 128;
}

private int GetMostRecentPostID(int forumId)
{
    return 317424;
}

您只需在母版页的代码隐藏(在 Page_Load 事件上)上挂钩 SiteMapResolveEventHandler,并提供一个返回您的自定义 SiteMapNode 的函数 - 例如示例中的 ExpandForumPaths - 然后将其作为委托传递给 SiteMapResolveEventHandler。

于 2013-06-28T10:57:44.020 回答