随笔-85  评论-51  文章-0  trackbacks-5
  参照petshop 4.0
/// <summary>
        /// 此方法用于确认用户输入的不是恶意信息
        /// </summary>
        /// <param name="text">用户输入信息</param>
        /// <param name="maxLength">输入的最大长度</param>
        /// <returns>处理后的输入信息</returns>
        public static string InputText(string text, int maxLength) {
            text = text.Trim();
            if (string.IsNullOrEmpty(text))
                return string.Empty;
            if (text.Length > maxLength)
                text = text.Substring(0, maxLength);
            //将网页中非法和有攻击性的符号替换掉,以防sql注入!返回正常数据
            text = Regex.Replace(text, "[\\s]{2,}", " "); // 2个或以上的空格
            text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n"); //<br> html换行符
            text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " "); //&nbsp;   html空格符
            text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty); // 任何其他的标签
            text = text.Replace("'", "''");// 单引号
            return text;
        }
posted on 2007-01-16 22:22 感動常在 阅读(453) 评论(1)  编辑 收藏 网摘 所属分类: 数据库心得

评论:
#1楼 2007-01-16 23:28 | myzerg      
太累了,sql注入用 command 不就屏蔽了么
  回复  引用  查看    



发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 622035




相关文章:

相关链接: