ASP.NET 过滤关键字

时间:2015/12/3 17:04:00来源:互联网 作者:flyso 点击: 909 次

/// <summary>
        /// 检测是否不带恶意字符
        /// </summary>
        /// <param name="InText"></param>
        /// <returns>如果参数存在不安全字符,则返回true</returns>
        public static bool SqlFilter(string InText)
        {
            string word = "and|exec|insert|select|delete|update|master|or|truncate|declare|.";
            if (InText == null)
                return false;
            foreach (string i in word.Split('|'))
            {
                if ((InText.ToLower().IndexOf(i + " ") > -1) || (InText.ToLower().IndexOf(" " + i) > -1))
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 编辑框过滤
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string EditRegText(string text)
        {
            if (!string.IsNullOrEmpty(text))
            {                
                text = text.Replace("'", "’");                
            }
          
            return text;
        }

        /// <summary>
        /// 过滤部分不安全字符
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string RegthisStr(string str)
        {
            return str = str.Replace(".", "").Replace("\"", "“").Replace("'", "‘").Replace("<", "<").Replace(">", ">");
        } 

Copyright © 2005 - 2016 flyso.cn. 飞搜 版权所有 鄂ICP备11002783号-3