예제 #1
0
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     if (AnonymousPage.Contains(filterContext.ActionDescriptor.ControllerDescriptor.ControllerName))
     {
         return;
     }
     //如果不存在身份信息
     if (CheckLogin)
     {
         if (ReturnType == "json")
         {
             JsonResult jsonRes = new JsonResult();
             MsgInfo    msgInfo = new MsgInfo
             {
                 IsError = true,
                 Msg     = "您已超时或未登陆,重新登陆",
                 MsgNo   = (int)ErrorEnum.超时未登录
             };
             jsonRes.Data = JsonConvert.SerializeObject(msgInfo);
         }
         else
         {
             ContentResult Content = new ContentResult();
             Content.Content      = string.Format("<script type='text/javascript'>window.location.href='{0}';</script>", "/login");
             filterContext.Result = Content;
         }
     }
 }
예제 #2
0
 /// <summary>
 /// 验证权限(action执行前会先执行这里)
 /// </summary>
 /// <param name="filterContext"></param>
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     if (AnonymousPage.Contains(filterContext.ActionDescriptor.ControllerDescriptor.ControllerName))
     {
         return;
     }
     //如果存在身份信息
     if (!HttpContext.Current.User.Identity.IsAuthenticated)
     {
         if (ReturnType == "json")
         {
             JsonResult jsonRes = new JsonResult();
             MsgInfo    msgInfo = new MsgInfo
             {
                 IsError = true,
                 Msg     = "您已超时或未登陆,重新登陆",
                 MsgNo   = (int)ErrorEnum.超时未登录
             };
             jsonRes.Data = JsonConvert.SerializeObject(msgInfo);
         }
         else
         {
             ContentResult Content = new ContentResult();
             Content.Content      = string.Format("<script type='text/javascript'>window.location.href='{0}';</script>", "/login/unlogin");
             filterContext.Result = Content;
         }
     }
     else if (OpenPrivileges)
     {
         if (!IsPrevilege(filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, FunCode))//验证权限
         {
             if (ReturnType == "json")
             {
                 JsonResult jsonRes = new JsonResult();
                 MsgInfo    msgInfo = new MsgInfo
                 {
                     IsError = true,
                     Msg     = "没有访问权限,请联系管理员",
                     MsgNo   = (int)ErrorEnum.没有权限
                 };
                 jsonRes.Data = JsonConvert.SerializeObject(msgInfo);
             }
             else
             {
                 //验证不通过
                 ContentResult Content = new ContentResult();
                 Content.Content      = "<script type='text/javascript'>alert('权限验证不通过!');history.go(-1);</script>";
                 filterContext.Result = Content;
             }
         }
     }
 }