asp.net防SQL注入
我做了一个网站,是用C#+SQL SERVER 2000做的。
没用存储过程。。
现在在数据库的一些表中的一些列中加了一段代码,我猜应该是SQL的注入,因为我在代码中没有加防注入的,而且我也不知道怎么加,加在哪??
请各位大虾指点指点。。。。
------解决方案-------------------- /// <summary>
       /// 该方法用来检测用户输入是否带有恶意
       /// </summary>
       /// <param name="text">用户输入的文字</param>
       /// <param name="maxlength">最大的长度</param>
       /// <returns>返回验证后的文字</returns>
       public static string InputText(string text, int maxlength)
       {
           text = text.ToLower().Trim();
           if (string.IsNullOrEmpty(text))
               return string.Empty;
           if (text.Length > maxlength)
               text = text.Substring(0, maxlength);
           text = Regex.Replace(text, "[\\s]{2,{", " ");
           text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n");	//<br>
           text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " ");	// 
           text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty);	//any other tags
           text = Regex.Replace(text,"=", "");
           text = Regex.Replace(text, "%", "");
           text = Regex.Replace(text, "'", "");
           text = Regex.Replace(text, "select", "");
           text = Regex.Replace(text, "insert", "");
           text = Regex.Replace(text, "delete", "");
           text = Regex.Replace(text, "or", "");
           text = Regex.Replace(text, "exec", "");
           text = Regex.Replace(text, "--", "");
           text = Regex.Replace(text, "and", "");
           text = Regex.Replace(text, "where", "");
           text = Regex.Replace(text, "update", "");
           text = Regex.Replace(text, "script", "");
           text = Regex.Replace(text, "iframe", "");
           text = Regex.Replace(text, "master", "");
           text = Regex.Replace(text, "exec", "");
           text = Regex.Replace(text, "<", "");
           text = Regex.Replace(text, ">", "");
           text = Regex.Replace(text, "\r\n", "");
           return text;
       }
------解决方案--------------------有游标把库里所有char,varchar,nvarchar的字段都替换(前提是没修改你的数据,只是添加了字符)
c#防注入的替换看看其他帖,到处都是
------解决方案--------------------用参数,不要直接拼SQL字符串
------解决方案--------------------恶意代码关键字过滤
------解决方案--------------------参考下
http://topic.csdn.net/u/20080521/09/dad3eaba-bfc7-483c-98cd-d310f9a76ff0.html?seed=596201967
http://topic.csdn.net/u/20080510/16/29c515de-c4d2-41fe-a1dc-df84de18f9b7.html
------解决方案--------------------用SqlParameter传参数
就不会有SQL注入的问题了
不要用拼接字符串
------解决方案--------------------
------解决方案--------------------