微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net: update/change SiteMapNode’s URL

Programmatically Modify Site-Map Nodes in Memory  (asp.net:  update/change SiteMapNode’s URL)

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 @R_759_4045@ion 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.Content object
// to obtain the ID.
private int GetMostRecentForumGroupID()
    {
     return 24;
    }


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


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

http://msdn.microsoft.com/en-us/library/ms178425.aspx

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/navigation/sitenavapi.aspx

http://www.eggheadcafe.com/community/aspnet/7/10014616/programmatically-modify-s.aspx

http://www.eggheadcafe.com/community/aspnet/7/10014602/how-do-you-update-a-sitem.aspx

http://dotnetslackers.com/VB_NET/re-113165_Adding_QueryString_Parameters_to_the_SiteMapNode.aspx

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐