常用的有哪些?给小段代码哈 O(∩_∩)O谢谢

解决方案 »

  1.   


        public static bool SafeCode(string code)
        {
            string ostr = "', ,=,%,declare,set,--";
            string[] str = Regex.Split(ostr, ",");        bool _re = true;        for (int i = 0; i < str.Length; i++)
            {
                if (code.ToLower().IndexOf(str[i]) > -1)
                {
                    _re = false;
                    return false;
                }
            }
            return _re;
        }
      

  2.   


        public bool validate(string str)
        {
            string strobj;
            bool test = false;
            for (int i = 0; i < str.Length; i++)
            {
                strobj = str.Substring(i, 1);
                if (strobj == "%" || strobj == "&" || strobj == "'" || strobj == "|" || strobj == "<" || strobj == ">")
                {
                    test = true;
                    break;
                }
            }
            return test;
        }
      

  3.   

    @canshu  参数化
    过滤字符也行!
      

  4.   

    一般
    sql.replace("'", "''");
    就可以了.
      

  5.   

    sql参数化
    http://topic.csdn.net/u/20090729/14/26381958-0D6E-4B90-BC90-D275E9621F93.html
      

  6.   

    asp里面我用函数过滤 .net刚接触 学习
      

  7.   

    用存储过程就不会出现SQL注入啦或者用下面这个方法也可以防止 一般的SQL注入    public static bool CheckSqlClauseIsValid(string strSqlClause)
        {
            int j;
            string s1, s2;
            string[] arrInvalid = { "insert ", "delete ", "update ", "exec ", "execute ", "drop ", "grant ", "backup ", "restore ", " sp_", " xp_" };
            strSqlClause = strSqlClause.ToLower().TrimStart();
            for (int i = 0; i < arrInvalid.Length; i++)
            {
                j = 0;
                while ((j = strSqlClause.IndexOf(arrInvalid[i], j + 1)) > -1)
                {
                    s1 = strSqlClause.Substring(0, j);
                    s2 = s1.Replace("'", "");
                    if ((s1.Length - s2.Length) % 2 == 0) return false;            }
            }
            return true;
        } 对于高级的嘛,你要自己去研究SQL 注入的 一些原理
      

  8.   

    不要拼接sql 吧
    存储过程等
      

  9.   

    参数化查询,linq等都可以防注入。
      

  10.   

    1。字符串查找,替换
    2。存储过程
    都可以实现SQL注入可以使用一些扫描工具扫一下,比如啊D 等