中国站长下载-为中国站长提供最好最全的建站资源! 首 页发布资源有事留言繁體中文
设为首页
加入收藏
联系我们
 
您当前的位置:中国站长下载 -> 文章中心 -> 网页编程 -> .NET编程 -> 文章内容  虚拟主机 域名注册 退出登录 用户管理
栏目导航
· ASP编程 · .NET编程
· PHP编程 · JSP编程
· CGI 专区
热门文章
· sndvol32 - sndvol3...
· [组图] FLASH:《大话李白》...
· 个人网站到底能赚多...
· [图文] Rundll.exe是病毒吗...
· [组图] Flash:制作MV
· 价值12万元的网站SE...
· 网站创业者,你需要...
· 一个成功的网站设计...
· [图文] FLASH:韩国导航条解...
· 中国网站的赚钱模式...
相关文章
· 使用ASP.NET开发移动...
· 使用ASP.NET中的一点...
· 使用ASP.NET程序来管...
· [组图] 使用ASP.NET 2.0中的...
· [组图] 使用ASP.NET 2.0中的...
· 使用asp.net2.0中的...
· 使用asp.net进行多关...
· 使用asp.net2.0中的...
· 使用ASP.NET Atlas ...
· 使用ASP.NET Atlas ...
使用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)。

 
[] [返回上一页] [打 印] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
中国站长下载
中国站长下载

本页只接受PR>=4 IT类站点连接,申请连接,谢谢您们的支持!希望我们的下载站能够真正帮到中国的站长们!
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图
Copyright © 2005-2006 ChinaZhan.Net. All Rights Reserved .