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

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

///
/// XML操作
///

private void XMLOperator()
{
XMLLoad();
string str = "";
foreach (XmlNode xn2 in xn1.ChildNodes)
{
str += "";
}
}
}
str += "
";
foreach (XmlNode xn in x.ChildNodes)
{
foreach (XmlNode xn1 in xn.ChildNodes)
{
str += xn1.Attributes["text"].Value;
str += "
";
str += xn2.Attributes["text"].Value;
str += "
";
Response.Write(str);
}
///
/// 加载XML文档
///

private void XMLLoad()
{
x.Load(Server.MapPath("~/Left.xml"));
}

///
/// 读取XML内容
///

///
///
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数据
复制代码 代码如下:


















































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

你可能感兴趣的:(asp.net下xml当作导航数据源实现动态权限)