zoukankan      html  css  js  c++  java
  • MVC授权

    public class CommonController : Controller
    {
     
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
            var actionName = filterContext.ActionDescriptor.ActionName;
            if (this.GetUserAuthorize(this.HttpContext.User.Identity.Name, controllerName, actionName))
            {
                base.OnAuthorization(filterContext);
            }
            else
            {
                const string ViewName = "~/Views/Account/Login.cshtml";
                var vr = new ViewResult { ViewName = ViewName };
                filterContext.Result = vr;
            }
        }
     
        private bool GetUserAuthorize(string userId,string controllerName,string actionName)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return false;
            }
     
            //访问数据库中相关的用户、角色、功能权限等表看是否具有访问此action的权限
              //有返回true,否则false
     
            return true;
        }
    

      

  • 相关阅读:
    UVA11375
    uva11806(容斥原理)
    uva10325(容斥原理)
    hdu4135(容斥原理)
    CF798
    多线程
    (转载)SVN 提交操作缩写(A D M R) .
    上不了网,如何判断
    (转载)myeclipse项目名称重命名
    mysql模糊查询
  • 原文地址:https://www.cnblogs.com/vjiedao/p/3529272.html
Copyright © 2011-2022 走看看