过滤脚本注入和SQL注入字符

       #region RemoveUnsafeString 过滤脚本注入和SQL注入字符
        /// 
        /// 过滤脚本注入和SQL注入字符
        /// 
        /// 目标字符串
        /// 过滤后的字符串
        public static string RemoveUnsafeString(string targetString)
        {
            if (string.IsNullOrEmpty(targetString))
            {
                return targetString;
            }
            targetString = Regex.Replace(targetString, @"]*?>.*?", string.Empty, RegexOptions.IgnoreCase);
            return Regex.Replace(targetString, @"[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']", string.Empty, RegexOptions.IgnoreCase);
        }
        #endregion

你可能感兴趣的:(C#)