|
|
| 使用asp.net2.0中的SiteMap中的一些问题(1) |
| 作者:不详 来源:不详 发布时间:2006-8-14 8:51:15 发布人:chinazhan |
减小字体
增大字体
SiteMap,网站地图,在网站建设的时候是很有用的。它可以直接绑定在Men和TreeView控件上,还有一个指示当前路径的SiteMapPath控件,也可以直接绑定。 这是他常用的xml定义: <siteMapNode url="Course/Group/GroupList.aspx" title="GroupAdmin" > 这个SiteMap的权限已经和Membership结合起来了,不同权限的用户所看到的地图已经被控制了。可以配置role属性来扩展例外的访问许可。注意,是例外的访问许可。 <siteMapNode url="Course/Tests/TestList.aspx" title="TestAdmin" role="student">这里有些介绍:http://zmsx.cnblogs.com/archive/2006/01/03/310381.aspx 简单的使用这里不作赘述,只是讨论一下怎么和扩展一下,让他可以访问资源时附带参数。 首先介绍这样一个资源:MySiteMapTool:http://quitgame.cnblogs.com/archive/2005/11/24/283910.aspx 这位仁兄已经提供了一个工具,可以在程序中转发带参数的请求 比如: MySiteMap.Forward("Details", "AlbumID={0}&Page={1}", 1, 4); 确是简单实用。 现在想要的功能是:因为各个液面都需要不同的参数,所以在没有这些参数的情况下就禁止用户访问那个页面,转而访问父一级页面,递归。 首先,SiteMap本身有个SiteMapResolve事件,在当前路径被解析时触发,这是一段来自MSDN的代码 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; } 做人要厚道,请注明转自chinazhan中国站长(www.ChinaZhan.com)。
|
| |
|
[]
[返回上一页]
[打 印]
[收 藏] |
|
| ∷相关文章评论∷ (评论内容只代表网友观点,与本站立场无关!) [更多评论...] |
|
|