asp.net下xml當(dāng)作導(dǎo)航數(shù)據(jù)源實(shí)現(xiàn)動(dòng)態(tài)權(quán)限
更新時(shí)間:2009年12月14日 23:10:04 作者:
如果有權(quán)限的話 可以通過節(jié)點(diǎn)的Roles屬性判斷當(dāng)前登陸的賬號(hào)角色名是否符合然后判斷輸出這樣的話您就可以直接操作XML數(shù)據(jù) 而不用考慮別的。
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內(nèi)容
/// </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數(shù)據(jù)
<?xml version="1.0" encoding="utf-8" ?>
<menu>
<submenu id="1" text="校區(qū)基本信息">
<item text="校區(qū)管理" href="SchoolBaseSet/SchoolManagement/SchoolInformation.aspx" href="SchoolBaseSet/SchoolManagement/SchoolInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長"></item>
<item text="班級(jí)管理" href="SchoolBaseSet/ClassManagement/ClassInformation.aspx" href="SchoolBaseSet/ClassManagement/ClassInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,班主任,院校長,教學(xué)主管,教學(xué)主任,校區(qū)考試專員" ></item>
<item text="學(xué)生信息管理" href="SchoolBaseSet/StudentInformation/StudentInformation.aspx" href="SchoolBaseSet/StudentInformation/StudentInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,班主任,教學(xué)主管,教學(xué)主任" ></item>
<item text="用戶信息管理" href="SchoolBaseSet/UserManagement/UserInformation.aspx" href="SchoolBaseSet/UserManagement/UserInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,教學(xué)主管,教學(xué)主任"></item>
<item text="教師審批管理" href="SchoolBaseSet/TeacherPass/TeacherPass.aspx" href="SchoolBaseSet/TeacherPass/TeacherPass.aspx" roles="教學(xué)主管,教學(xué)主任,校區(qū)考試專員"></item>
<item text="切換教師角色" href="SchoolBaseSet/TeacherPass/RolesChange.aspx" href="SchoolBaseSet/TeacherPass/RolesChange.aspx" roles="校區(qū)考試專員"></item>
</submenu>
<submenu id="2" text="學(xué)生成績管理">
<item text="成績綜合管理" href="StudentGradeManagement/StudentGradedescirption/StudentGradeAll.aspx" href="StudentGradeManagement/StudentGradedescirption/StudentGradeAll.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,班主任,教學(xué)主管,教學(xué)主任" ></item>
<item text="學(xué)生成績管理" href="StudentGradeManagement/StudentGradedescirption/StudentInformation.aspx" href="StudentGradeManagement/StudentGradedescirption/StudentInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,班主任,教學(xué)主管,教學(xué)主任" ></item>
</submenu>
<submenu id="3" text="數(shù)據(jù)字典設(shè)置">
<item text="專業(yè)管理" href="DataDictionary/Specialty/Specialties.aspx" href="DataDictionary/Specialty/Specialties.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="課程管理" href="DataDictionary/Course/Courses.aspx" href="DataDictionary/Course/Courses.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="專業(yè)課程管理" href="DataDictionary/CourseInSpecialty/CouserInSpecialty.aspx" href="DataDictionary/CourseInSpecialty/CouserInSpecialty.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="角色管理" href="DataDictionary/Rolse/Roles.aspx" href="DataDictionary/Rolse/Roles.aspx" roles="超級(jí)管理員"></item>
<item text="管理員管理" href="DataDictionary/AdminUser/AdministratorUser.aspx" href="DataDictionary/AdminUser/AdministratorUser.aspx" roles="超級(jí)管理員" ></item>
<item text="Logo圖標(biāo)管理" href="DataDictionary/Logo/EditLogo.aspx" href="DataDictionary/Logo/EditLogo.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,教學(xué)主管,教學(xué)主任" ></item>
<item text="學(xué)號(hào)長度設(shè)置" href="DataDictionary/StudentCodeSet/StudentCodeLenghtInf.aspx" href="DataDictionary/StudentCodeSet/StudentCodeLenghtInf.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="恢復(fù)設(shè)置管理" href="DataDictionary/RemoveSchool/RemoveAllSchool.aspx" href="DataDictionary/RemoveSchool/RemoveAllSchool.aspx" roles="超級(jí)管理員" ></item>
</submenu>
<submenu id="4" text="考試操作管理">
<item text="考試類型管理" href="ExamManagement/ExamType/ExamTypeInformation.aspx" href="ExamManagement/ExamType/ExamTypeInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="試卷模板管理" href="ExamManagement/ExamTemplate/ExamTemplateInformation.aspx" href="ExamManagement/ExamTemplate/ExamTemplateInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="試題類型管理" href="ExamManagement/ExaminationType/ExaminationInformation.aspx" href="ExamManagement/ExaminationType/ExaminationInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="試題題目管理" href="ExamManagement/ExamQuestion/QuestionInformation.aspx" href="ExamManagement/ExamQuestion/QuestionInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="考試申請(qǐng)管理" href="ExamManagement/ExamApplication/ExamApplicationInformation.aspx" href="ExamManagement/ExamApplication/ExamApplicationInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="試卷下載管理" href="ExamManagement/ExamDownLoad/ExamDownLoadInformation.aspx" href="ExamManagement/ExamDownLoad/ExamDownLoadInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="試卷刪除管理" href="ExamManagement/ExamPaperDelete/ExamPaperClear.aspx" href="ExamManagement/ExamPaperDelete/ExamPaperClear.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
</submenu>
<submenu id="5" text="報(bào)表信息管理">
<item text="緩考補(bǔ)考報(bào)表" href="ReportInformation/StudentExamState/StudentExamState.aspx" href="ReportInformation/StudentExamState/StudentExamState.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,班主任,教學(xué)主管,教學(xué)主任,校區(qū)考試專員" ></item>
<item text="校區(qū)考試報(bào)表" href="ReportInformation/ExamGrade/ExamGradeReport.aspx" href="ReportInformation/ExamGrade/ExamGradeReport.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,教學(xué)主管,教學(xué)主任,校區(qū)考試專員" ></item>
<item text="班級(jí)課程報(bào)表" href="ReportInformation/StudentExamByClass/StudentExamReport.aspx" href="ReportInformation/StudentExamByClass/StudentExamReport.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,班主任,教學(xué)主管,教學(xué)主任,校區(qū)考試專員" ></item>
</submenu>
<submenu id="6" text="日志操作管理">
<item text="登陸日志管理" href="LoginManagement/LogLogins.aspx" href="LoginManagement/LogLogins.aspx" roles="超級(jí)管理員" ></item>
<item text="操作日志管理" href="LoginManagement/LogOpeations.aspx" href="LoginManagement/LogOpeations.aspx" roles="超級(jí)管理員" ></item>
<item text="日志導(dǎo)出" href="LoginManagement/ErportLog.aspx" href="LoginManagement/ErportLog.aspx" roles="超級(jí)管理員" >
</item>
</submenu>
<submenu id="7" text="個(gè)人信息管理">
<item text="個(gè)人資料修改" href="PersonalManagement/PersonalManagement.aspx" href="PersonalManagement/PersonalManagement.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,班主任,教學(xué)主管,教學(xué)主任,校區(qū)考試專員" ></item>
</submenu>
</menu>
從上面的簡單代碼可以看到 如果有權(quán)限的話 可以通過節(jié)點(diǎn)的Roles屬性判斷當(dāng)前登陸的賬號(hào)角色名是否符合然后判斷輸出這樣的話您就可以直接操作XML數(shù)據(jù) 而不用考慮別的。
復(fù)制代碼 代碼如下:
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內(nèi)容
/// </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數(shù)據(jù)
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8" ?>
<menu>
<submenu id="1" text="校區(qū)基本信息">
<item text="校區(qū)管理" href="SchoolBaseSet/SchoolManagement/SchoolInformation.aspx" href="SchoolBaseSet/SchoolManagement/SchoolInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長"></item>
<item text="班級(jí)管理" href="SchoolBaseSet/ClassManagement/ClassInformation.aspx" href="SchoolBaseSet/ClassManagement/ClassInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,班主任,院校長,教學(xué)主管,教學(xué)主任,校區(qū)考試專員" ></item>
<item text="學(xué)生信息管理" href="SchoolBaseSet/StudentInformation/StudentInformation.aspx" href="SchoolBaseSet/StudentInformation/StudentInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,班主任,教學(xué)主管,教學(xué)主任" ></item>
<item text="用戶信息管理" href="SchoolBaseSet/UserManagement/UserInformation.aspx" href="SchoolBaseSet/UserManagement/UserInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,教學(xué)主管,教學(xué)主任"></item>
<item text="教師審批管理" href="SchoolBaseSet/TeacherPass/TeacherPass.aspx" href="SchoolBaseSet/TeacherPass/TeacherPass.aspx" roles="教學(xué)主管,教學(xué)主任,校區(qū)考試專員"></item>
<item text="切換教師角色" href="SchoolBaseSet/TeacherPass/RolesChange.aspx" href="SchoolBaseSet/TeacherPass/RolesChange.aspx" roles="校區(qū)考試專員"></item>
</submenu>
<submenu id="2" text="學(xué)生成績管理">
<item text="成績綜合管理" href="StudentGradeManagement/StudentGradedescirption/StudentGradeAll.aspx" href="StudentGradeManagement/StudentGradedescirption/StudentGradeAll.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,班主任,教學(xué)主管,教學(xué)主任" ></item>
<item text="學(xué)生成績管理" href="StudentGradeManagement/StudentGradedescirption/StudentInformation.aspx" href="StudentGradeManagement/StudentGradedescirption/StudentInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,班主任,教學(xué)主管,教學(xué)主任" ></item>
</submenu>
<submenu id="3" text="數(shù)據(jù)字典設(shè)置">
<item text="專業(yè)管理" href="DataDictionary/Specialty/Specialties.aspx" href="DataDictionary/Specialty/Specialties.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="課程管理" href="DataDictionary/Course/Courses.aspx" href="DataDictionary/Course/Courses.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="專業(yè)課程管理" href="DataDictionary/CourseInSpecialty/CouserInSpecialty.aspx" href="DataDictionary/CourseInSpecialty/CouserInSpecialty.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="角色管理" href="DataDictionary/Rolse/Roles.aspx" href="DataDictionary/Rolse/Roles.aspx" roles="超級(jí)管理員"></item>
<item text="管理員管理" href="DataDictionary/AdminUser/AdministratorUser.aspx" href="DataDictionary/AdminUser/AdministratorUser.aspx" roles="超級(jí)管理員" ></item>
<item text="Logo圖標(biāo)管理" href="DataDictionary/Logo/EditLogo.aspx" href="DataDictionary/Logo/EditLogo.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,教學(xué)主管,教學(xué)主任" ></item>
<item text="學(xué)號(hào)長度設(shè)置" href="DataDictionary/StudentCodeSet/StudentCodeLenghtInf.aspx" href="DataDictionary/StudentCodeSet/StudentCodeLenghtInf.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="恢復(fù)設(shè)置管理" href="DataDictionary/RemoveSchool/RemoveAllSchool.aspx" href="DataDictionary/RemoveSchool/RemoveAllSchool.aspx" roles="超級(jí)管理員" ></item>
</submenu>
<submenu id="4" text="考試操作管理">
<item text="考試類型管理" href="ExamManagement/ExamType/ExamTypeInformation.aspx" href="ExamManagement/ExamType/ExamTypeInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="試卷模板管理" href="ExamManagement/ExamTemplate/ExamTemplateInformation.aspx" href="ExamManagement/ExamTemplate/ExamTemplateInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="試題類型管理" href="ExamManagement/ExaminationType/ExaminationInformation.aspx" href="ExamManagement/ExaminationType/ExaminationInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="試題題目管理" href="ExamManagement/ExamQuestion/QuestionInformation.aspx" href="ExamManagement/ExamQuestion/QuestionInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="考試申請(qǐng)管理" href="ExamManagement/ExamApplication/ExamApplicationInformation.aspx" href="ExamManagement/ExamApplication/ExamApplicationInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="試卷下載管理" href="ExamManagement/ExamDownLoad/ExamDownLoadInformation.aspx" href="ExamManagement/ExamDownLoad/ExamDownLoadInformation.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
<item text="試卷刪除管理" href="ExamManagement/ExamPaperDelete/ExamPaperClear.aspx" href="ExamManagement/ExamPaperDelete/ExamPaperClear.aspx" roles="超級(jí)管理員,系統(tǒng)管理員" ></item>
</submenu>
<submenu id="5" text="報(bào)表信息管理">
<item text="緩考補(bǔ)考報(bào)表" href="ReportInformation/StudentExamState/StudentExamState.aspx" href="ReportInformation/StudentExamState/StudentExamState.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,班主任,教學(xué)主管,教學(xué)主任,校區(qū)考試專員" ></item>
<item text="校區(qū)考試報(bào)表" href="ReportInformation/ExamGrade/ExamGradeReport.aspx" href="ReportInformation/ExamGrade/ExamGradeReport.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,教學(xué)主管,教學(xué)主任,校區(qū)考試專員" ></item>
<item text="班級(jí)課程報(bào)表" href="ReportInformation/StudentExamByClass/StudentExamReport.aspx" href="ReportInformation/StudentExamByClass/StudentExamReport.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,班主任,教學(xué)主管,教學(xué)主任,校區(qū)考試專員" ></item>
</submenu>
<submenu id="6" text="日志操作管理">
<item text="登陸日志管理" href="LoginManagement/LogLogins.aspx" href="LoginManagement/LogLogins.aspx" roles="超級(jí)管理員" ></item>
<item text="操作日志管理" href="LoginManagement/LogOpeations.aspx" href="LoginManagement/LogOpeations.aspx" roles="超級(jí)管理員" ></item>
<item text="日志導(dǎo)出" href="LoginManagement/ErportLog.aspx" href="LoginManagement/ErportLog.aspx" roles="超級(jí)管理員" >
</item>
</submenu>
<submenu id="7" text="個(gè)人信息管理">
<item text="個(gè)人資料修改" href="PersonalManagement/PersonalManagement.aspx" href="PersonalManagement/PersonalManagement.aspx" roles="超級(jí)管理員,系統(tǒng)管理員,院校長,班主任,教學(xué)主管,教學(xué)主任,校區(qū)考試專員" ></item>
</submenu>
</menu>
從上面的簡單代碼可以看到 如果有權(quán)限的話 可以通過節(jié)點(diǎn)的Roles屬性判斷當(dāng)前登陸的賬號(hào)角色名是否符合然后判斷輸出這樣的話您就可以直接操作XML數(shù)據(jù) 而不用考慮別的。
相關(guān)文章
asp.net下按鈕點(diǎn)擊后禁用的實(shí)現(xiàn)代碼
有時(shí)候?yàn)榱瞬蛔層脩暨B續(xù)的點(diǎn)擊某按鈕,我們會(huì)選擇將其在點(diǎn)擊后禁用。2010-09-09
Asp.net在線備份、壓縮和修復(fù)Access數(shù)據(jù)庫示例代碼
這篇文章主要介紹了Asp.net如何在線備份、壓縮和修復(fù)Access數(shù)據(jù)庫,需要的朋友可以參考下2014-03-03
在?.NET?中使用?FixedTimeEquals?應(yīng)對(duì)計(jì)時(shí)攻擊的例子
在計(jì)算機(jī)安全中,計(jì)時(shí)攻擊(Timing attack)是旁道攻擊 (Side-channel attack) 的一種,而旁道攻擊是根據(jù)計(jì)算機(jī)處理過程發(fā)出的信息進(jìn)行分析,這篇文章主要介紹了在?.NET?中使用?FixedTimeEquals?應(yīng)對(duì)計(jì)時(shí)攻擊,需要的朋友可以參考下2022-06-06
asp.net IList查詢數(shù)據(jù)后格式化數(shù)據(jù)再綁定控件
這篇文章送給.net初學(xué)者或者遇到類似問題的朋友,就是IList如何格式化數(shù)據(jù)再綁定,我看到網(wǎng)上沒有多少朋友講到這方面的最基本的問題,現(xiàn)在我簡單說說吧,代碼我就截取其中一些講,如果不明白的朋友可以留言或者聯(lián)系我。2009-11-11
ASP.NET WebAPi(selfhost)實(shí)現(xiàn)文件同步或異步上傳
這篇文章主要介紹了ASP.NET WebAPi(selfhost)實(shí)現(xiàn)文件同步或異步上傳,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11

