|
|
| 使用asp.net2.0中的SiteMap中的一些问题(2) |
| 作者:不详 来源:不详 发布时间:2006-8-14 8:51:11 发布人:chinazhan |
减小字体
增大字体
这段代码只是给当前路径加载参数。 曾经尝试过使用类似的方法,但是SiteMapPath搞定了,Menu就绑定不上数据了。并且只能处理一部分数据。 后来,结合SiteMapTool那个类,又写出几个函数可以解决这个问题 这是修改之后的sitemap文件,加了一个配置项:rule,里面的参数是这个页面需要的参数。如果当前上下文没有这些参数,那么禁止用户访问这个页面。 <siteMapNode url="Course/Group/GroupDetail.aspx" title="Group Detail" rule="cid;gid"> 这是两个函数,递归处理所有的路径。 private string MakeURL(SiteMapNode node) { node.ReadOnly = false; //find the static url string url = MySiteMap.FindForward(node.Title); if (node["rule"] != null && node["rule"].Length > 0) { //if have the rule,then check string[] paramSet = node["rule"].Split(';'); //check for (int i = 0; i < paramSet.Length; i++) { //if request have not such a param, then invoke self to check his parent if (HttpContext.Current.Request.Params[paramSet[i]] == null) return MakeURL(node.ParentNode); } //if pass ,then add all the params and return the value url += "?"; for (int i = 0; i < paramSet.Length; i++) { string key = paramSet[i]; //'cid'--->'cid=1'. the former format is like : rule='cid;tid' url = url + key + "=" + HttpContext.Current.Request.Params[key] + "&"; } return url.Substring(0, url.Length - 1); //remove last '&' } else { //if there is no rule then return the url directly return url; } } private void ReBindData(SiteMapNode root) { string url = MakeURL(root); if (url != "") root.Url = url; for (int i = 0; i < root.ChildNodes.Count; i++) { ReBindData(root.ChildNodes[i]); } }在ReBindData里面递归调用MakeUrl函数。 MakeUrl函数里面调用的MySiteMap.FindForward函数就是来自那位http://quitgame.cnblogs.com/archive/2005/11/24/283910.aspx的实现。 不过应用的是后需要做一些改动:他原来的实现是用静态的类如此加载 //SiteMapNodeCollection smc = SiteMap.RootNode.GetAllNodes(); //siteMapCol = new NameValueCollection(); //IEnumerator ie = smc.GetEnumerator(); //while (ie.MoveNext()) //{ // siteMapCol[((SiteMapNode)ie.Current).Title] = ((SiteMapNode)ie.Current).Url; //}但是,由于用户在没有登陆的时候,限于权限,它能访问的页面有限,所以SiteMap.RootNode.GetAllNodes();得到的不是所有数据,可能只是一部分或者0。 改动方式就是自己写一个函数,直接读取xml文件,递归获取所有数据定义。 出处:BLOG 随心所欲 做人要厚道,请注明转自chinazhan中国站长(www.ChinaZhan.com)。
|
| |
|
[]
[返回上一页]
[打 印]
[收 藏] |
|
| ∷相关文章评论∷ (评论内容只代表网友观点,与本站立场无关!) [更多评论...] |
|
|