private bool ValidateUrl() { //DataRow[] drUser = GetCache().Tables["Emp_User"] // .Select(string.Format(@"UserId='{0}'", string.IsNullOrEmpty(AuthUser.GetCurrentUser().userID) ? "0" : AuthUser.GetCurrentUser().userID)); //if (drUser.Length == 0) return false; //changed by Pluto Mei 2014-1-6 //to avoid some spcific condition cause userId will not be integar and throw exceptions //improve program's robustness var userId = AuthUser.GetCurrentUser().userID; var intUserId = 0; int.TryParse(userId, out intUserId); if (GetCache().Tables["Emp_User"] == null) { //return false; SetCache(); } DataRow[] drUser = GetCache().Tables["Emp_User"].Select(string.Format(@"UserId={0}", intUserId)); if (drUser.Length == 0) { return(false); } string requestUrl = HttpContext.Current.Request.Path; DataTable dtAllModule = GetCache().Tables["Sys_Module"]; DataTable dtAllFunction = GetCache().Tables["Sys_Function"]; bool existUrl = dtAllModule.Select(string.Format(@"ModuleUrl='{0}'", requestUrl)).Length == 0; existUrl &= dtAllFunction.Select(string.Format(@"FunctionUrl='{0}'", requestUrl)).Length == 0; if (existUrl) { return(true); } //List<string> userUrlList = GetUserUrl(AuthUser.GetCurrentUser().userID); //if (userUrlList.Contains(requestUrl, StringComparer.OrdinalIgnoreCase)) return true; //return false; var userUrlList = GetUrlListByUserId(intUserId); return(userUrlList.Contains(requestUrl, StringComparer.OrdinalIgnoreCase)); }
private void ValidateFunction(ControlCollection cc) { foreach (Control ct in cc) { //标记btnSubmit_FID_1004010101 const string flag = "_FID_"; string regTxt = @"^\w+_FID_(\d){10}\w*$"; Regex reg = new Regex(regTxt); if (!string.IsNullOrEmpty(ct.ID) && reg.Match(ct.ID).Success) { int startIndex = ct.ID.IndexOf(flag); int functionId = int.Parse(ct.ID.Substring(startIndex + flag.Length, 10)); ct.Visible = VisibleFunction(functionId, AuthUser.GetCurrentUser().userID); } if (ct.Controls.Count > 0) { ValidateFunction(ct.Controls); } } }