新建一个类BaseController,这个类继承Controller类.并重写Controller里的OnActionExecuting函数:
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
//用户权限集
var listRightID=new List<int>();
var blnNoRight = false;
var strControllerName = filterContext.Controller.ToString();
if (strControllerName.Contains("AController"))
if (!listRightID.Contains(Convert.ToInt32(GlobalMember.EnumRight.BookType)))
blnNoRight = true;
if (strControllerName.Contains("BTypeController"))
if (!listRightID.Contains(Convert.ToInt32(GlobalMember.EnumRight.MembershipType)))
blnNoRight = true;
if (strControllerName.Contains("CController"))
if (!listRightID.Contains(Convert.ToInt32(GlobalMember.EnumRight.Role)))
blnNoRight = true;
//无权限跳转
if(blnNoRight){
Response.Redirect("Main/Error");
}
}
然后在需要用到的Controller继承BaseController就OK了。嘿嘿。