public AuthorizationSetting GetAuthorizationSettings() { try { var config = WebConfigurationManager.OpenWebConfiguration("~"); var section = config.GetSection("system.web/authorization") as AuthorizationSection; var authSetting = new AuthorizationSetting(); // Don't evaluate the last rule because it seems to always be to allow *. int count = 1; int numberOfRules = section.Rules.Count; foreach (AuthorizationRule rule in section.Rules) { if (count == numberOfRules) { break; } if (rule.Action.ToString().ToLower() == "allow") { authSetting.AllowedRoles = string.Concat(rule.Roles); authSetting.AllowedUsers = string.Concat(rule.Users); } if (rule.Action.ToString().ToLower() == "deny") { authSetting.DeniedRoles = string.Concat(rule.Roles); authSetting.DeniedUsers = string.Concat(rule.Users); } count++; } return(authSetting); } catch (Exception ex) { Logger.LogException(ex); throw Helper.CreateHttpResponseException(ex, "Error Getting Authorization Settings"); } }
public IActionResult Save(AuthorizationSetting settings) { try { if (settings.Type == FunctionPowerType.Department) { departmentDataService.UpdateFunctionPowers(settings.NodeID, settings.AppInfoID, settings.FunctionPowerIDList); } else if (settings.Type == FunctionPowerType.Role) { roleDataService.UpdateFunctionPowers(settings.NodeID, settings.AppInfoID, settings.FunctionPowerIDList); } return(Json(new APIResult <AuthorizationSetting>(settings))); } catch (Exception ex) { return(Json(new APIResult <AuthorizationSetting>(errors: ex.Message) { data = settings })); } }