当前位置:首页 >> 资讯

使用asnet20中的SiteMa中节能

2020-10-21 05:03:15  双城汽车网

SiteMap,站地图,在站建设的时候是很有用的。它可以直接绑定在Men和TreeView控件上,还有一个指示当前路径的SiteMapPath控件,也可以直接绑定。

这是他常用的xml定义:siteMapNode url="Course/Group/px" title="GroupAdmin" 这个SiteMap的权限已经和Membership结合起来了,不同权限的用户所看到的地图已经被控制了。可以配置role属性来扩展例外的访问许可。注意,是例外的访问许可。

siteMapNode url="Course/Tests/px" title="TestAdmin" role="student"这里有些介绍:

简单的使用这里不作赘述,只是讨论一下怎么和扩展一下,让他可以访问资源时附带参数。

首先介绍这样一个资源:MySiteMapTool:这位仁兄已经提供了一个工具,可以在程序中转发带参数的请求比如: rward("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. teMapResolve += new SiteMapResolveEventHandler(pandForumPaths);}

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 l 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 = one(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)

{ l = l + "?PostID=" + String();}

if ((null != (tempNode = rentNode)) (0 != forumID))

{ l = l + "?ForumID=" + String();}

if ((null != (tempNode = rentNode)) (0 != forumGroupID))

{ l = l + "?ForumGroupID=" + String();}

return currentNode;}

这段代码只是给当前路径加载参数。

曾经尝试过使用类似的方法,但是SiteMapPath搞定了,Menu就绑定不上数据了。并且只能处理一部分数据。

后来,结合SiteMapTool那个类,又写出几个函数可以解决这个问题这是修改之后的sitemap文件,加了一个配置项:rul保持颈椎、腰椎健康e,里面的参数是这个页面需要的参数。如果当前上下文没有这些参数,那么禁止用户访问这个页面。

siteMapNode url="Course/Group/px" title="Group Detail" rule="cid;gid"这是两个函数,递归处理所有的路径。 private string MakeURL(SiteMapNode node)

{ adOnly = false;//find the static url string url = ndForward(tle);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 ngth; i++)

{ //if request have not such a param, then invoke self to check his parent if (rams[paramSet[i]] == null)

return MakeURL(rentNode);} //if pass ,then add all the params and return the value url += "?";for (int i = 0; i ngth; i++)

{ string key = paramSet[i];//'cid'——'cid=1'. the former format is like : rule='cid;tid' url = url + key + "=" + rams[key] + "";} return bstring(0, ngth - 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 != "")

l = url;for (int i = 0; i unt; i++)

{ ReBindData(ildNodes[i]);} }在ReBindData里面递归调用MakeUrl函数。

MakeUrl函数里面调用的ndForward函数就是来自那位的实现。

不过应用的是后需要做一些改动:他原来的实现是用静态的类如此加载//SiteMapNodeCollection smc = tAllNodes();//siteMapCol = new NameValueCollection();

//IEnumerator ie = tEnumerator();//while (veNext())

//{ // siteMapCol[((SiteMapNode)rrent)。Title] = ((SiteMapNode)rrent)。Url;//}但是,由于用户在没有登陆的时候,限于权限,它能访问的页面有限,所以tAllNodes();得到的不是所有数据,可能只是一部分或者0.改动方式就是自己写一个函数,直接读取xml文件,递归获取所有数据定义。

查看本文来源

丁桂薏芽健脾凝胶功效
保健医药资讯
新生儿肚子胀怎么办
友情链接