public static IEnumerable <Feature> GetFeature(int?userId) { List <Feature> features = null; using (FeatureService srv = new FeatureService()) { features = srv.GetFeats(userId); } if (features != null) { //若此會員有此功能,回傳true var query = features.Where(f => f.ActionName == "Index"); if (query.Any()) { return(query); } } return(null); }
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { /**/ //Feature feature = featSrv.GetFeats(IdentityHelper.UserId).FirstOrDefault(); var feat = featSrv.GetFeats(IdentityHelper.UserId).FirstOrDefault(); if (feat != null) { //導到別頁 filterContext.HttpContext.Response.RedirectToRoute(new { controller = feat.ControllerName, action = feat.ActionName }); } else { //用URL filterContext.Result = new RedirectToRouteResult( new System.Web.Routing.RouteValueDictionary { { "action", "Logout" }, { "controller", "Home" } }); } //filterContext.Result = new ViewResult { ViewName = AuthorizationFailView }; }