码迷,mamicode.com
首页 > 其他好文 > 详细

用户验证

时间:2016-12-27 07:32:57      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:targe   target   int   string   value   没有   info   str   inf   

#region 用户验证
/// <summary>
/// 用户验证过滤器
/// </summary>
public class UserAuthentication : AuthorizeAttribute
{
IMenu imenu = UserEngine.GetProvider<IMenu>();

/// <summary>
/// 执行前验证
/// </summary>
public override void OnAuthorization(AuthorizationContext filterContext)
{
base.OnAuthorization(filterContext);
if (!UserContext.Instance.IsLogined)
{
filterContext.Result = new RedirectResult("/home/Login");
//filterContext.Result = new JsonResult { Data = new { Result = 1, Content = "您没有权限!", Redirect = "/Home/Login" }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
else
{
IList<ActionInfo> actionList = UserContext.Instance.User.GetActions();
IList<MenuActionInfo> menuActionList = imenu.GetMenuActionListByActions(actionList);
IDictionary<int, MenuInfo> menuInDB = imenu.GetMenuDictionary();


var isMenuInDbQuery = from m in menuInDB.Values
where (!string.IsNullOrEmpty(m.TargetUrl.Trim())&&filterContext.HttpContext.Request.Url.PathAndQuery.ToUpper().Contains(m.TargetUrl.ToUpper()))
select m;

if(isMenuInDbQuery.ToList().Count()>0)
{


var menuQuery = from ma in menuActionList
where (!string.IsNullOrEmpty(ma.TargetUrl.Trim())&&filterContext.HttpContext.Request.Url.PathAndQuery.ToUpper().Contains(ma.TargetUrl.ToUpper()))
select ma.TargetUrl;

if (menuQuery.ToList().Count() < 1)
{
filterContext.Result = new RedirectResult("/Home/Login");
}
}
}
}
}
#endregion

用户验证

标签:targe   target   int   string   value   没有   info   str   inf   

原文地址:http://www.cnblogs.com/cosea/p/6224398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!