欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net下xml当作导航数据源实现动态权限

程序员文章站 2024-03-09 10:47:53
cs文件里面的代码 复制代码 代码如下: using system; using system.collections; using system.configuratio...
cs文件里面的代码
复制代码 代码如下:

using system;
using system.collections;
using system.configuration;
using system.data;
using system.linq;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.htmlcontrols;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.xml;
using system.io;
namespace root
{
public partial class webusercontrol1 : system.web.ui.usercontrol
{
xmldocument x = new xmldocument();
protected void page_load(object sender, eventargs e)
{
if (!ispostback)
{
xmloperator();
}
}

/// <summary>
/// xml操作
/// </summary>
private void xmloperator()
{
xmlload();
string str = "<table><tr><td>";
foreach (xmlnode xn in x.childnodes)
{
foreach (xmlnode xn1 in xn.childnodes)
{
str += xn1.attributes["text"].value;
str += "</td></tr>";
foreach (xmlnode xn2 in xn1.childnodes)
{
str += "<tr><td>";
str += xn2.attributes["text"].value;
str += "</td></tr>";
}
}
}
str += "</table>";
response.write(str);
}
/// <summary>
/// 加载xml文档
/// </summary>
private void xmlload()
{
x.load(server.mappath("~/left.xml"));
}

/// <summary>
/// 读取xml内容
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
private dataset readxml(string path)
{
dataset ds = new dataset();
filestream fs = null;
streamreader reader = null;
try
{
fs = new filestream(path, filemode.open, fileaccess.read);
reader = new streamreader(fs, system.text.encoding.utf8);
ds.readxml(reader);
return ds;
}
finally
{
fs.close();
reader.close();
}
}
}
}

xml数据
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8" ?>
<menu>
<submenu id="1" text="校区基本信息">
<item text="校区管理" href="schoolbaseset/schoolmanagement/schoolinformation.aspx" href="schoolbaseset/schoolmanagement/schoolinformation.aspx" roles="超级管理员,系统管理员,院校长"></item>
<item text="班级管理" href="schoolbaseset/classmanagement/classinformation.aspx" href="schoolbaseset/classmanagement/classinformation.aspx" roles="超级管理员,系统管理员,班主任,院校长,教学主管,教学主任,校区考试专员" ></item>
<item text="学生信息管理" href="schoolbaseset/studentinformation/studentinformation.aspx" href="schoolbaseset/studentinformation/studentinformation.aspx" roles="超级管理员,系统管理员,院校长,班主任,教学主管,教学主任" ></item>
<item text="用户信息管理" href="schoolbaseset/usermanagement/userinformation.aspx" href="schoolbaseset/usermanagement/userinformation.aspx" roles="超级管理员,系统管理员,院校长,教学主管,教学主任"></item>
<item text="教师审批管理" href="schoolbaseset/teacherpass/teacherpass.aspx" href="schoolbaseset/teacherpass/teacherpass.aspx" roles="教学主管,教学主任,校区考试专员"></item>
<item text="切换教师角色" href="schoolbaseset/teacherpass/roleschange.aspx" href="schoolbaseset/teacherpass/roleschange.aspx" roles="校区考试专员"></item>
</submenu>
<submenu id="2" text="学生成绩管理">
<item text="成绩综合管理" href="studentgrademanagement/studentgradedescirption/studentgradeall.aspx" href="studentgrademanagement/studentgradedescirption/studentgradeall.aspx" roles="超级管理员,系统管理员,院校长,班主任,教学主管,教学主任" ></item>
<item text="学生成绩管理" href="studentgrademanagement/studentgradedescirption/studentinformation.aspx" href="studentgrademanagement/studentgradedescirption/studentinformation.aspx" roles="超级管理员,系统管理员,院校长,班主任,教学主管,教学主任" ></item>
</submenu>
<submenu id="3" text="数据字典设置">
<item text="专业管理" href="datadictionary/specialty/specialties.aspx" href="datadictionary/specialty/specialties.aspx" roles="超级管理员,系统管理员" ></item>
<item text="课程管理" href="datadictionary/course/courses.aspx" href="datadictionary/course/courses.aspx" roles="超级管理员,系统管理员" ></item>
<item text="专业课程管理" href="datadictionary/courseinspecialty/couserinspecialty.aspx" href="datadictionary/courseinspecialty/couserinspecialty.aspx" roles="超级管理员,系统管理员" ></item>
<item text="角色管理" href="datadictionary/rolse/roles.aspx" href="datadictionary/rolse/roles.aspx" roles="超级管理员"></item>
<item text="管理员管理" href="datadictionary/adminuser/administratoruser.aspx" href="datadictionary/adminuser/administratoruser.aspx" roles="超级管理员" ></item>
<item text="logo图标管理" href="datadictionary/logo/editlogo.aspx" href="datadictionary/logo/editlogo.aspx" roles="超级管理员,系统管理员,教学主管,教学主任" ></item>
<item text="学号长度设置" href="datadictionary/studentcodeset/studentcodelenghtinf.aspx" href="datadictionary/studentcodeset/studentcodelenghtinf.aspx" roles="超级管理员,系统管理员" ></item>
<item text="恢复设置管理" href="datadictionary/removeschool/removeallschool.aspx" href="datadictionary/removeschool/removeallschool.aspx" roles="超级管理员" ></item>
</submenu>
<submenu id="4" text="考试操作管理">
<item text="考试类型管理" href="exammanagement/examtype/examtypeinformation.aspx" href="exammanagement/examtype/examtypeinformation.aspx" roles="超级管理员,系统管理员" ></item>
<item text="试卷模板管理" href="exammanagement/examtemplate/examtemplateinformation.aspx" href="exammanagement/examtemplate/examtemplateinformation.aspx" roles="超级管理员,系统管理员" ></item>
<item text="试题类型管理" href="exammanagement/examinationtype/examinationinformation.aspx" href="exammanagement/examinationtype/examinationinformation.aspx" roles="超级管理员,系统管理员" ></item>
<item text="试题题目管理" href="exammanagement/examquestion/questioninformation.aspx" href="exammanagement/examquestion/questioninformation.aspx" roles="超级管理员,系统管理员" ></item>
<item text="考试申请管理" href="exammanagement/examapplication/examapplicationinformation.aspx" href="exammanagement/examapplication/examapplicationinformation.aspx" roles="超级管理员,系统管理员" ></item>
<item text="试卷下载管理" href="exammanagement/examdownload/examdownloadinformation.aspx" href="exammanagement/examdownload/examdownloadinformation.aspx" roles="超级管理员,系统管理员" ></item>
<item text="试卷删除管理" href="exammanagement/exampaperdelete/exampaperclear.aspx" href="exammanagement/exampaperdelete/exampaperclear.aspx" roles="超级管理员,系统管理员" ></item>
</submenu>
<submenu id="5" text="报表信息管理">
<item text="缓考补考报表" href="reportinformation/studentexamstate/studentexamstate.aspx" href="reportinformation/studentexamstate/studentexamstate.aspx" roles="超级管理员,系统管理员,院校长,班主任,教学主管,教学主任,校区考试专员" ></item>
<item text="校区考试报表" href="reportinformation/examgrade/examgradereport.aspx" href="reportinformation/examgrade/examgradereport.aspx" roles="超级管理员,系统管理员,院校长,教学主管,教学主任,校区考试专员" ></item>
<item text="班级课程报表" href="reportinformation/studentexambyclass/studentexamreport.aspx" href="reportinformation/studentexambyclass/studentexamreport.aspx" roles="超级管理员,系统管理员,院校长,班主任,教学主管,教学主任,校区考试专员" ></item>
</submenu>
<submenu id="6" text="日志操作管理">
<item text="登陆日志管理" href="loginmanagement/loglogins.aspx" href="loginmanagement/loglogins.aspx" roles="超级管理员" ></item>
<item text="操作日志管理" href="loginmanagement/logopeations.aspx" href="loginmanagement/logopeations.aspx" roles="超级管理员" ></item>
<item text="日志导出" href="loginmanagement/erportlog.aspx" href="loginmanagement/erportlog.aspx" roles="超级管理员" >
</item>
</submenu>
<submenu id="7" text="个人信息管理">
<item text="个人资料修改" href="personalmanagement/personalmanagement.aspx" href="personalmanagement/personalmanagement.aspx" roles="超级管理员,系统管理员,院校长,班主任,教学主管,教学主任,校区考试专员" ></item>
</submenu>
</menu>

从上面的简单代码可以看到 如果有权限的话 可以通过节点的roles属性判断当前登陆的账号角色名是否符合然后判断输出这样的话您就可以直接操作xml数据 而不用考虑别的。