protected void Application_Start() { ControllerActionRepository actionAuthorizationRepo = new ControllerActionRepository(); actionAuthorizationRepo.UpdateActionList(); AppSettingRepository appSettingRepository = new AppSettingRepository(); appSettingRepository.Reload(); AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); var copy = ViewEngines.Engines.ToList(); ViewEngines.Engines.Clear(); foreach (var item in copy) { ViewEngines.Engines.Add(new ProfilingViewEngine(item)); } GlobalFilters.Filters.Add(new ProfilingActionFilter()); ModelBinders.Binders.Add(typeof(decimal?), new NullableDecimalModelBinder()); ModelBinders.Binders.Add(typeof(decimal), new NullableDecimalModelBinder()); }
public ActionResult UpdateControllerAction() { ControllerActionRepository actionAuthorizationRepo = new ControllerActionRepository(); actionAuthorizationRepo.UpdateActionList(); return(RedirectToAction("Index", "Home")); }
protected void Application_Start() { RoleRepository repo = new RoleRepository(); repo.InitRole(); ControllerActionRepository actionAuthorizationRepo = new ControllerActionRepository(); actionAuthorizationRepo.UpdateActionList(); AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); }
public static MvcHtmlString ActionLinkWithRoles_Old <T>(this HtmlHelper html, string linkText, Expression <Func <T, ActionResult> > action) where T : Controller { ControllerActionRepository actionAuthorizationRepo = new ControllerActionRepository(); actionAuthorizationRepo.UpdateActionList(); MvcHtmlString htmlStr = null; ReflectedControllerDescriptor controllerDes = new ReflectedControllerDescriptor(typeof(T)); string controllerName = controllerDes.ControllerName; MethodCallExpression methodExp = action.Body as MethodCallExpression; if (methodExp != null) { string actionName = methodExp.Method.Name; //List<ActionDescriptor> actionDescriptorList = controllerDes.GetCanonicalActions().Where(r => r.ActionName == actionName).ToList(); //ActionDescriptor actionDes = actionDescriptorList.FirstOrDefault(); ControllerActionRepository controllerActionRepository = new ControllerActionRepository(); ControllerAction controllerAction = controllerActionRepository.GetActionWithVerbHttpGet(controllerName, actionName); if (controllerAction != null) { MVCAuthorizationRepository mvcAuthorizationRepository = new MVCAuthorizationRepository(); List <string> roles = mvcAuthorizationRepository.GetRolesByControllerAction(controllerAction); CustomAuthorize customAuthorize = new CustomAuthorize() { AuthorizedRoles = roles.ToArray() }; if (customAuthorize.Authorize(html.ViewContext.HttpContext)) { htmlStr = html.ActionLink(linkText, actionName, controllerName); } } // if (actionDes != null) // { // List<CustomAuthorize> customAuthorizeList = actionDes.GetFilters().AuthorizationFilters.Where(r => r is CustomAuthorize).Select(r => r as CustomAuthorize).ToList(); // if (customAuthorizeList.Count > 0) // { // if (customAuthorizeList.Select(r => r.Authorize(html.ViewContext.HttpContext)).Any(r => r)) // { // htmlStr = html.ActionLink(linkText, actionName, controllerName); // } // } // else // { // htmlStr = html.ActionLink(linkText, actionName, controllerName); // } // //List<CustomAuthorize> ofController = controllerDes.GetCustomAttributes(typeof(CustomAuthorize), true).Select(r => r as CustomAuthorize).ToList(); // //List<CustomAuthorize> ofAction = actionDes.GetCustomAttributes(typeof(CustomAuthorize), true).Select(r => r as CustomAuthorize).ToList(); // //List<CustomAuthorize> ofAll = new List<CustomAuthorize>(); // //ofAll.AddRange(ofController); // //ofAll.AddRange(ofAction); // //string[] roles = ofAll.SelectMany(r => r.AuthorizedRoles).Distinct().ToArray(); // //string[] users = ofAll.SelectMany(r => r.AuthorizedUsers).Distinct().ToArray(); // //if (HttpContext.Current.User.HasAnyRole(roles) // // || users.Contains(OAMSSetting.Username)) // //{ // // htmlStr = html.ActionLink(linkText, actionName, controllerName); // //} // } } return(htmlStr); }