权限设置(飞机订票系统案例)
第一种方法、(页面)
缺点:没有办法阻止用户通过网页地址(页面路径)进入某页面
1.在主页面上写一个方法(主页面—其他页面的根页面,通过主页面跳转)
function JurisdictionMenu()
2.获取页面上全部菜单
var dirIdModlarName = {
"PNR": "PNR",
"电子票证": "ELectromicTicket",
…………}
3.发送提交请求
$.post("/Main/SelectModularJurisdiction", { time: (new Date()).getTime().toString() }, function (objModulars) {}
4.判断
if (objModulars == "") {
window.location.href = "/";
} else {
for (key in objModulars) {
var obj = objModulars[key];
if (obj.ID == 0) {
var modularName = obj.ModularName;
var elId = dirIdModlarName[modularName];
console.log(elId);
$("#" + elId).remove();//去掉没有的权限对应的菜单
}
}
}
5.回到控制器接收请求
public ActionResult SelectModularJurisdiction()
6.判断
if (Session["userID"] != null) //与登录时所保存的名称(大小写)一致 Session["userID"] = dbUser.userID;
6.读取权限信息(查询权限)
var temModulars = from tabPermission in myModel.S_Permission
join tabModule in myModel.S_Module
on tabPermission.moduleID equals tabModule.moduleID
join tabUser in myModel.S_User
on tabPermission.UserTypeID equals tabUser.userTypeID
where tabUser.userID == userId && tabModule.blFun == false
select new
{
ID = tabModule.moduleID,//模块ID
Name = tabModule.moduleDescrible.Trim() //模块描述