asp.net下xml當作導航資料來源實現動態許可權

來源:互聯網
上載者:User

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資料 而不用考慮別的。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.