예제 #1
0
        protected string Actionname;       //当前Action小写名称

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            if (!AuthUtil.CheckLogin())
            {
                return;
            }

            Controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
            Actionname     = filterContext.ActionDescriptor.ActionName.ToLower();

            var function = this.GetType().GetMethods().FirstOrDefault(u => u.Name.ToLower() == Actionname);

            if (function == null)
            {
                throw new Exception("未能找到Action");
            }

            var authorize = function.GetCustomAttribute(typeof(AuthenticateAttribute));

            CurrentModule = AuthUtil.GetCurrentUser().Modules.FirstOrDefault(u => u.Url.ToLower().Contains(Controllername));
            //当前登录用户没有Action记录&&Action有authenticate标识
            if (authorize != null && CurrentModule == null)
            {
                filterContext.Result = new RedirectResult("/Login/Index");
                return;
            }

            var version = ConfigurationManager.AppSettings["version"];

            if (version == "demo" && Request.HttpMethod == "POST")
            {
                throw new HttpException(400, "演示版本,不能进行该操作,当前模块:" + Controllername + "/" + Actionname);
            }
        }