public override void OnAuthorization(AuthorizationContext filterContext) { //no1: 判断是否登录 var user = filterContext.HttpContext.Session?["User"] as UserDto; var controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; var action = filterContext.ActionDescriptor.ActionName; var method = filterContext.HttpContext.Request.HttpMethod; var url = filterContext.HttpContext.Request.RawUrl; var categoryKey = filterContext.HttpContext.Request.QueryString["CategoryKey"]; if (user != null) { var token = CacheHelper.GetCache(user.LoginName); var info = AuthConfigXmlHelper.GetAuthConfigByXml(Api.PhysicsUrl + "/Config/AuthConfig.xml" , url, controller, action, method, categoryKey); _roles = BusinessHelper.BreakUpOptions(info.Roles, ','); if (!AuthManager.TryAuthorize(filterContext, token.ToString(), _roles)) { var respMessage = ResponseProvider.Error("你没有被授权访问此资源。", 401); //异常处理模块接入 } } base.OnAuthorization(filterContext); }
/// <summary> /// 创建复选框 /// </summary> /// <param name="model"></param> /// <returns></returns> private static string CreateButtonList(ModelFieldDto model) { var sw = new StringWriter(); var writer = new HtmlTextWriter(sw); writer.AddAttribute("class", model.ControlType == "multi-radio" ? "rule-multi-radio" : "rule-multi-checkbox"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute("class", "multi-check"); writer.AddAttribute("value", "{{content.ContentValue." + model.Code + "}}"); writer.AddAttribute("type", "hidden"); writer.RenderBeginTag(HtmlTextWriterTag.Input); writer.RenderEndTag(); writer.AddAttribute("id", "txt" + model.Code); writer.RenderBeginTag(HtmlTextWriterTag.Span); var array = BusinessHelper.BreakUpOptions(model.ItemOption, '|'); for (var i = 0; i < array.Length; i++) { var obj = array[i].Split(','); #region 构建input writer.AddAttribute("id", "txt" + model.Code + "_" + i); writer.AddAttribute("name", model.Code); writer.AddAttribute("type", model.ControlType == "multi-radio" ? "radio" : "checkbox"); writer.AddAttribute("value", obj[0]); writer.RenderBeginTag(HtmlTextWriterTag.Input); writer.RenderEndTag(); #endregion #region 构建label writer.AddAttribute("for", "txt" + model.Code + "_" + i); writer.RenderBeginTag(HtmlTextWriterTag.Label); writer.Write(obj[1]); writer.RenderEndTag(); #endregion } writer.WriteLine(); writer.RenderEndTag(); writer.RenderEndTag(); return(writer.InnerWriter.ToString()); }
public ActionResult Save(RoleDto model) { var saveState = BusinessHelper.BuildSaveState(Request); var resourceList = Request["resourceList"]; var array = BusinessHelper.BreakUpStr(resourceList, ','); var arrayStr = BusinessHelper.BreakUpOptions(resourceList, ','); _roleBll.HttpPostSave(model, saveState, array); var actionList = Request["actionList"]; var actionArr = BusinessHelper.BreakUpOptions(actionList, '|'); //资源授权 AuthConfigXmlHelper.UpateRolesAuthConfigByXml(Api.PhysicsUrl + "/Config/AuthConfig.xml" , arrayStr, model.Code); //Action授权 AuthConfigXmlHelper.UpateActionRolesAuthConfigByXml(Api.PhysicsUrl + "/Config/AuthConfig.xml" , model.Code, actionArr); return(RedirectToAction("Index", "Role")); }