/// <summary> /// 检验IP的可访问性(白名单优先于黑名单),如果同时白名单、黑名名单都有同一IP,则也允许访问。 /// </summary> /// <param name="ipAddress"></param> /// <returns></returns> public bool ValidateIPAccess(string ipAddress, int userId) { bool result = false; IBlackIP dal = baseDal as IBlackIP; List <BlackIPInfo> whiteList = dal.FindByUser(userId, AuthrizeType.白名单); if (whiteList.Count > 0) { result = IsInList(whiteList, ipAddress); return(result); //白名单优先于黑名单,在白名单则通过 } List <BlackIPInfo> blackList = dal.FindByUser(userId, AuthrizeType.黑名单); if (blackList.Count > 0) { bool flag = IsInList(blackList, ipAddress); return(!flag);//不在则通过,在就禁止 } //当黑白名单都为空的时候,那么返回true,则默认不禁止 return(true); }
/// <summary> /// 根据用户ID和授权类型获取列表 /// </summary> /// <param name="userId">用户ID</param> /// <param name="type">授权类型</param> /// <returns></returns> public List <BlackIPInfo> FindByUser(int userId, AuthrizeType type) { IBlackIP dal = baseDal as IBlackIP; return(dal.FindByUser(userId, type)); }
/// <summary> /// 根据用户ID和授权类型获取列表 /// </summary> /// <param name="userId">用户ID</param> /// <param name="type">授权类型</param> /// <returns></returns> public List <BlackIPInfo> FindByUser(Int32 userId, AuthorizeType authorizeType) { return(dal.FindByUser(userId, authorizeType)); }