选择显示字体大小

使用asp.net2.0中的sitemap中的一些问题

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;
}

 

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

曾经尝试过使用类似的方法,但是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 随心所欲


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons