Use xml in asp.net as a navigation data source to achieve dynamic Permissions

Source: Internet
Author: User

Code in the cs File
Copy codeThe Code is as follows:
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 operation
/// </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>
/// Load the XML document
/// </Summary>
Private void XMLLoad ()
{
X. Load (Server. MapPath ("~ /Left. xml "));
}

/// <Summary>
/// Read XML content
/// </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 data
Copy codeThe Code is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Menu>
<Submenu id = "1" text = "campus basic information">
<Item text = "campus management" href = "SchoolBaseSet/SchoolManagement/SchoolInformation. aspx "href =" SchoolBaseSet/SchoolManagement/SchoolInformation. aspx "roles =" Super administrator, system administrator, school principal "> </item>
<Item text = "Class Management" href = "SchoolBaseSet/ClassManagement/ClassInformation. aspx "href =" SchoolBaseSet/ClassManagement/ClassInformation. aspx "roles =" Super administrator, system administrator, class teacher, school principal, teaching Director, teaching Director, campus examination specialist "> </item>
<Item text = "student information management" href = "SchoolBaseSet/StudentInformation. aspx "href =" SchoolBaseSet/StudentInformation. aspx "roles =" Super administrator, system administrator, school principal, class teacher, teaching Director, teaching director "> </item>
<Item text = "User Information Management" href = "SchoolBaseSet/UserManagement/UserInformation. aspx "href =" SchoolBaseSet/UserManagement/UserInformation. aspx "roles =" Super administrator, system administrator, school principal, teaching Director, teaching director "> </item>
<Item text = "instructor approval management" href = "SchoolBaseSet/TeacherPass. aspx "href =" SchoolBaseSet/TeacherPass. aspx "roles =" Teaching Director, teaching Director, campus examination specialist "> </item>
<Item text = "" href = "SchoolBaseSet/TeacherPass/RolesChange. aspx "href =" SchoolBaseSet/TeacherPass/RolesChange. aspx "roles =" campus examiner "> </item>
</Submenu>
<Submenu id = "2" text = "Student Achievement Management">
<Item text = "overall score management" href = "StudentGradeManagement/StudentGradedescirption/StudentGradeAll. aspx "href =" StudentGradeManagement/StudentGradedescirption/StudentGradeAll. aspx "roles =" Super administrator, system administrator, school principal, class teacher, teaching Director, teaching director "> </item>
<Item text = "Student Score Management" href = "StudentGradeManagement/StudentGradedescirption/StudentInformation. aspx "href =" StudentGradeManagement/StudentGradedescirption/StudentInformation. aspx "roles =" Super administrator, system administrator, school principal, class teacher, teaching Director, teaching director "> </item>
</Submenu>
<Submenu id = "3" text = "data dictionary Settings">
<Item text = "professional management" href = "DataDictionary/Specialty/Specialties. aspx "href =" DataDictionary/Specialty/Specialties. aspx "roles =" Super administrator, system administrator "> </item>
<Item text = "Course Management" href = "DataDictionary/Course/Courses. aspx "href =" DataDictionary/Course/Courses. aspx "roles =" Super administrator, system administrator "> </item>
<Item text = "Professional Course Management" href = "DataDictionary/CourseInSpecialty/CouserInSpecialty. aspx "href =" DataDictionary/CourseInSpecialty/CouserInSpecialty. aspx "roles =" Super administrator, system administrator "> </item>
<Item text = "role management" href = "DataDictionary/Rolse/Roles. aspx "href =" DataDictionary/Rolse/Roles. aspx "roles =" Super administrator "> </item>
<Item text = "administrator management" href = "DataDictionary/AdminUser/AdministratorUser. aspx "href =" DataDictionary/AdminUser/AdministratorUser. aspx "roles =" Super administrator "> </item>
<Item text = "Logo icon management" href = "DataDictionary/Logo/EditLogo. aspx "href =" DataDictionary/Logo/EditLogo. aspx "roles =" Super administrator, system administrator, Teaching Supervisor, teaching director "> </item>
<Item text = "student ID length Settings" href = "DataDictionary/StudentCodeSet/StudentCodeLenghtInf. aspx "href =" DataDictionary/StudentCodeSet/StudentCodeLenghtInf. aspx "roles =" Super administrator, system administrator "> </item>
<Item text = "Restore settings management" href = "DataDictionary/RemoveSchool/RemoveAllSchool. aspx "href =" DataDictionary/RemoveSchool/RemoveAllSchool. aspx "roles =" Super administrator "> </item>
</Submenu>
<Submenu id = "4" text = "Exam operation management">
<Item text = "Exam type management" href = "ExamManagement/ExamType/ExamTypeInformation. aspx "href =" ExamManagement/ExamType/ExamTypeInformation. aspx "roles =" Super administrator, system administrator "> </item>
<Item text = "Exam template management" href = "ExamManagement/ExamTemplate/ExamTemplateInformation. aspx "href =" ExamManagement/ExamTemplate/ExamTemplateInformation. aspx "roles =" Super administrator, system administrator "> </item>
<Item text = "question type management" href = "ExamManagement/ExaminationType/ExaminationInformation. aspx "href =" ExamManagement/ExaminationType/ExaminationInformation. aspx "roles =" Super administrator, system administrator "> </item>
<Item text = "question and question management" href = "ExamManagement/ExamQuestion/QuestionInformation. aspx "href =" ExamManagement/ExamQuestion/QuestionInformation. aspx "roles =" Super administrator, system administrator "> </item>
<Item text = "Exam Application Management" href = "ExamManagement/ExamApplication/ExamApplicationInformation. aspx "href =" ExamManagement/ExamApplication/ExamApplicationInformation. aspx "roles =" Super administrator, system administrator "> </item>
<Item text = "Exam download management" href = "ExamManagement/ExamDownLoad/ExamDownLoadInformation. aspx "href =" ExamManagement/ExamDownLoad/ExamDownLoadInformation. aspx "roles =" Super administrator, system administrator "> </item>
<Item text = "Exam deletion management" href = "ExamManagement/ExamPaperDelete/ExamPaperClear. aspx "href =" ExamManagement/ExamPaperDelete/ExamPaperClear. aspx "roles =" Super administrator, system administrator "> </item>
</Submenu>
<Submenu id = "5" text = "report information management">
<Item text = "retake Report" href = "ReportInformation/StudentExamState. aspx "href =" ReportInformation/StudentExamState. aspx "roles =" Super administrator, system administrator, school principal, class teacher, teaching Director, teaching Director, campus examination specialist "> </item>
<Item text = "campus Examination Report" href = "ReportInformation/ExamGrade/ExamGradeReport. aspx "href =" ReportInformation/ExamGrade/ExamGradeReport. aspx "roles =" Super administrator, system administrator, school principal, teaching Director, teaching Director, campus examination specialist "> </item>
<Item text = "class course report" href = "ReportInformation/StudentExamByClass/StudentExamReport. aspx "href =" ReportInformation/StudentExamByClass/StudentExamReport. aspx "roles =" Super administrator, system administrator, school principal, class teacher, teaching Director, teaching Director, campus examination specialist "> </item>
</Submenu>
<Submenu id = "6" text = "log operation management">
<Item text = "Logon log management" href = "LoginManagement/LogLogins. aspx" href = "LoginManagement/LogLogins. aspx" roles = "Super administrator"> </item>
<Item text = "Operation Log Management" href = "LoginManagement/LogOpeations. aspx" href = "LoginManagement/LogOpeations. aspx" roles = "Super administrator"> </item>
<Item text = "log export" href = "LoginManagement/ErportLog. aspx" href = "LoginManagement/ErportLog. aspx" roles = "Super administrator">
</Item>
</Submenu>
<Submenu id = "7" text = "personal information management">
<Item text = "personal data modification" href = "PersonalManagement/PersonalManagement. aspx "href =" PersonalManagement/PersonalManagement. aspx "roles =" Super administrator, system administrator, school principal, class teacher, teaching Director, teaching Director, campus examination specialist "> </item>
</Submenu>
</Menu>

From the simple code above, we can see that if you have the permission, you can use the Roles attribute of the node to determine whether the role name of the currently logged-in account is correct and then determine whether the output is so that you can directly operate the XML data without consideration. others.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.