コード例 #1
0
ファイル: BaseController.cs プロジェクト: singlag888/cp-1
        protected CheckData CheckAccess(System.Web.Routing.RequestContext requestContext)
        {
            CheckData result = new CheckData();

            /*默认请求*/
            result.ActionName     = ActionName;
            result.ControllerName = ControllerName;
            result.ResultType     = 1;
            if (AMLoginUser.mu001 == 0)
            {
                if (UILoginUser.u001 == 0)
                {
                    return(result);
                }
            }
            string[] menuIDs = (string[])requestContext.HttpContext.Session["PGIDs"];
            /*得到当前请求的一些数据*/
            GetServerData(requestContext);
            /*从缓存中取出菜单*/
            roleList = serMenu.GetMenuListByCache();
            /*找出当前请求的控制器、动作对应的记录*/
            var findRoleList = roleList.Where(exp => exp.sm006 == ControllerName && exp.sm007 == ActionName).ToList();
            /*查找出菜单*/
            var roleCount = findRoleList.Count();
            /*请求存在子级,带method,即当前请求methodType不为空情况下*/
            List <DBModel.wgs004> roleSubList = new List <DBModel.wgs004>();

            if (false == string.IsNullOrEmpty(MethodType))
            {
                var methodTypeString = MethodType;
                roleSubList = findRoleList.Where(exp => exp.sm008 != null && exp.sm008.Contains(methodTypeString)).ToList();
            }
            /*请求不存在菜单中*/
            if (0 == roleCount)
            {
            }
            #region 如果权限存在
            DicMethod = serSystem.GetReqeustTypeS(true);
            if (0 < roleCount)
            {
                var            curRole = findRoleList[0];
                DBModel.wgs011 runLog  = new DBModel.wgs011();
                runLog.log001 = System.Guid.NewGuid();
                runLog.sm005  = findRoleList[0].sm005;
                runLog.sm002  = findRoleList[0].sm002;
                runLog.sm001  = findRoleList[0].sm001;
                if (0 < roleSubList.Count)
                {
                    runLog.sm005 = roleSubList[0].sm005;
                    runLog.sm002 = roleSubList[0].sm002;
                    runLog.sm001 = roleSubList[0].sm001;
                    curRole      = roleSubList[0];
                }
                /*是否记录*/
                if (0 == curRole.sm014)
                {
                    return(result);
                }
                runLog.log002 = ControllerName;
                runLog.log003 = ActionName;
                runLog.log004 = DateTime.Now;
                if (ControllerName == "AM" && AMLoginUser.mu001 != 0)
                {
                    runLog.u001 = AMLoginUser.mu001;
                    runLog.u002 = AMLoginUser.mu002.Trim();
                    runLog.u003 = _NWC.GeneralValidate.IsNullOrEmpty(AMLoginUser.mu003) ? "" : AMLoginUser.mu003.Trim();
                }
                else if (ControllerName == "UI" && UILoginUser.u001 != 0)
                {
                    runLog.u001 = UILoginUser.u001;
                    runLog.u002 = UILoginUser.u002.Trim();
                    runLog.u003 = _NWC.GeneralValidate.IsNullOrEmpty(UILoginUser.u003) ? "" : UILoginUser.u003.Trim();
                }
                runLog.log005 = _NWC.RequestHelper.GetUserIP(requestContext.HttpContext.Request);
                runLog.log006 = int.Parse(requestContext.HttpContext.Request.ServerVariables["REMOTE_PORT"]);
                runLog.log011 = DicMethod[requestContext.HttpContext.Request.ServerVariables["REQUEST_METHOD"]];
                runLog.log012 = requestContext.HttpContext.Request.ServerVariables["HTTP_REFERER"];
                runLog.log013 = requestContext.HttpContext.Request.ServerVariables["URL"];
                runLog.log014 = requestContext.HttpContext.Request.ServerVariables["SERVER_NAME"];
                if ("POST" == requestContext.HttpContext.Request.ServerVariables["REQUEST_METHOD"])
                {
                    runLog.log007 = Newtonsoft.Json.JsonConvert.SerializeObject(DicForm);
                }
                if (0 < DicQueryString.Count)
                {
                    runLog.log009 = Newtonsoft.Json.JsonConvert.SerializeObject(DicQueryString);
                }
                if (0 < DicCookie.Count())
                {
                    runLog.log008 = Newtonsoft.Json.JsonConvert.SerializeObject(DicCookie);
                }
                if (0 < DicSession.Count())
                {
                    runLog.log010 = Newtonsoft.Json.JsonConvert.SerializeObject(DicSession);
                }
                serSystem.AddMenuLog(runLog);
                /*最高管理官记录后其他不需要任何验证*/
                if (1 == AMLoginUser.mu001)
                {
                    return(result);
                }
                else if (1 == curRole.sm013 && "AM" == ControllerName)
                {
                    if (0 == menuIDs.Count(exp => exp == curRole.sm001.ToString()))
                    {
                        throw new Exception(string.Format("无权限访问{0}", curRole.sm004));
                    }
                }
            }
            #endregion
            return(result);
        }