/// <summary> /// 获取签名前拼接字符串 /// </summary> public static string GetStringSignTemp <T>(T model, string SignKey, bool ParaAsc = true, StringComparison StrCompar = StringComparison.Ordinal, string SplitStr = "&", Func <string, string, string> KeyValueJoin = null, BindingFlags?bindingAttr = null) { StringBuilder stringSignTemp = new StringBuilder(); if (model != null) { List <PropertyInfo> ProList; if (bindingAttr.HasValue) { ProList = model.GetType().GetProperties(bindingAttr.Value).ToList(); } else { ProList = model.GetType().GetProperties().ToList(); } if (ParaAsc) { ProList.Sort((x, y) => string.Compare(x.Name, y.Name, StrCompar)); } else { ProList.Sort((x, y) => - (string.Compare(x.Name, y.Name, StrCompar))); } for (int i = 0; i < ProList.Count; i++) { if (THelper.GetCustomAttribute <NoSignAttribute>(ProList[i]) == null) { object ProIValue = ProList[i].GetValue(model, null); if (ProIValue != null) { if (!string.IsNullOrEmpty(ProIValue.ToString().Trim())) { if (stringSignTemp.Length > 0) { stringSignTemp.Append(SplitStr); } if (KeyValueJoin != null) { stringSignTemp.Append(KeyValueJoin(ProList[i].Name, ProIValue.ToString())); } else { stringSignTemp.Append(ProList[i].Name + "=" + ProIValue.ToString()); } } } } } } if (!string.IsNullOrEmpty(SignKey)) { stringSignTemp.Append(SignKey); } return(stringSignTemp.ToString()); }
/// <summary> /// 在调用操作方法前调用。 /// </summary> /// <param name="filterContext">有关当前请求和操作的信息</param> protected override void OnActionExecuting(ActionExecutingContext filterContext) { //获取登录用户信息 _model_login = GetLoginCookie(); if (_model_login != null) { _model_login = GetLoginModel(_model_login); } //检查是否需要特殊验证 CheckAttribute CheckAttribute = THelper.GetCustomAttribute <CheckAttribute>(filterContext.Controller.GetType().GetMethod(filterContext.ActionDescriptor.ActionName, (System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase))); if (CheckAttribute == null) { CheckAttribute = THelper.GetCustomAttribute <CheckAttribute>(filterContext.Controller.GetType()); } //特殊验证(登录) if (CheckAttribute != null) { CheckLoginDefault = CheckAttribute.CheckLogin; //检查是否是否需要验证登录 } if (CheckLoginDefault) { //检测是否已登录成功 if (Model_Login == null) { filterContext.Result = Redirect((string.IsNullOrEmpty(LoginFailUrl)) ? "/Home/Index" : LoginFailUrl); } { //特殊验证(权限) if (CheckAttribute != null) { CheckPermissionsDefault = CheckAttribute.CheckPermissions; //检查是否是否需要验证权限 } if (CheckPermissionsDefault) { if (!CheckPermissions()) { filterContext.Result = Redirect((string.IsNullOrEmpty(PermissionsFailUrl)) ? "/Home/Index" : PermissionsFailUrl); } } } } ViewBag.Model_Login = Model_Login; base.OnActionExecuting(filterContext); }