asp.net下xml当作导航数据源实现动态权限
2024-07-10 12:42:47
供稿:网友
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>