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); }
private UnitOfWork() { this._context = new CapInnovativeIdiaDbContext(); Idia = new IdiaRepository(_context); User = new UserRepository(_context); Role = new RoleRepository(_context); Account = new AccountRepository(_context); Controller = new ControllerRepository(_context); ControllerAction = new ControllerActionRepository(_context); UserAccess = new UserAccessRepository(_context); Team = new TeamRepository(_context); IdiaCategory = new IdiaCategoryRepository(_context); IdiaProposal = new IdiaProposalRepository(_context); IdiaStatus = new IdiaStatusRepository(_context); }
public static bool IsAuthorize(string controllerName, string actionName, bool isPost = false) { var isAuthorize = false; ControllerActionRepository controllerActionRepository = new ControllerActionRepository(); ControllerAction controllerAction = controllerActionRepository.GetAction(controllerName, actionName, isPost); if (controllerAction != null) { MVCAuthorizationRepository mvcAuthorizationRepository = new MVCAuthorizationRepository(); List <string> roles = mvcAuthorizationRepository.GetRolesByControllerAction(controllerAction); CustomAuthorize customAuthorize = new CustomAuthorize() { AuthorizedRoles = roles.ToArray() }; isAuthorize = customAuthorize.Authorize(); } return(isAuthorize); }
public static MvcHtmlString ActionLinkWithRoles <T>(this HtmlHelper html, string linkText, Expression <Func <T, ActionResult> > action, RouteValueDictionary routeValues = null, IDictionary <string, object> htmlAttributes = null, bool isPost = false) where T : Controller { MvcHtmlString htmlStr = MvcHtmlString.Create(""); ReflectedControllerDescriptor controllerDes = new ReflectedControllerDescriptor(typeof(T)); string controllerName = controllerDes.ControllerName; MethodCallExpression methodExp = action.Body as MethodCallExpression; if (methodExp != null) { string actionName = methodExp.Method.Name; ControllerActionRepository controllerActionRepository = new ControllerActionRepository(); ControllerAction controllerAction = controllerActionRepository.GetAction(controllerName, actionName, isPost); 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)) { if (isPost && htmlAttributes == null) { htmlStr = MvcHtmlString.Create("<input type='submit' value='" + linkText + "' />"); } else { htmlStr = html.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes); } } } } return(htmlStr); }
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); }