int ID = Convert.ToInt32(Request.QueryString["ID"]);
string MyID = ReplaceSQLChar(ID.ToString().Trim(), true);//这段是不是脱裤子放屁呢????
ReplaceSQLChar类如下:
            if (strInput == String.Empty)
            {
                return String.Empty;
            }
            else
            {
                if (ReplaceSQLAndOr)
                {
                    strInput = strInput.Replace("and", "");
                    strInput = strInput.Replace("AND", "");
                    strInput = strInput.Replace("And", "");
                    strInput = strInput.Replace("or", "");
                    strInput = strInput.Replace("OR", "");
                    strInput = strInput.Replace("Or", "");
                }
                strInput = strInput.Replace(":", "");
                strInput = strInput.Replace("'", "");
                strInput = strInput.Replace("‘", "");
                strInput = strInput.Replace(";", "");
                strInput = strInput.Replace(",", "");
                strInput = strInput.Replace("?", "");
                strInput = strInput.Replace("<", "");
                strInput = strInput.Replace(">", "");
                strInput = strInput.Replace("(", "");
                strInput = strInput.Replace(")", "");
                strInput = strInput.Replace("@", "");
                strInput = strInput.Replace("=", "");
                strInput = strInput.Replace("+", "");
                strInput = strInput.Replace("*", "");
                strInput = strInput.Replace("&", "");
                strInput = strInput.Replace("#", "");
                strInput = strInput.Replace("%", "");
                strInput = strInput.Replace("$", "");
                //返回已过滤掉SQL字符的字符串
                return strInput;
            }

解决方案 »

  1.   

    你说的没错,多此一举了.既然已强制转换为int了.就不必过滤特殊字符了.
      

  2.   

    一丁点的用途:又把int转换成string了
      

  3.   

    不过最好用int.tryparse来转换否则你要加上try catch来捕获错误.
      

  4.   


    问题是就是要string类型的,哈哈
      

  5.   

    那干嘛不直接String ID = Request.QueryString["ID"].Trim();
      

  6.   


    这就是我就不明白的地方了,为了防止SQL注入。
      

  7.   

    asp.net里不需要这么麻烦,不是asp,现在是21世纪了兄弟,哈哈
      

  8.   

    如果我想保存邮箱怎么办,[email protected]就会保存为aaabbb.com