一有答案立即给分~~~想求一下C#中对所有输入串进行过滤得代码(防注入的) 如果楼主指的是sql注入.1.用参数化写法2.string类型.将所有'号替换成'' ,另外生成sql前判断数字类型,日期类型的合法性即可. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public string Input(string input) { return input.Replace("'","''").TrimEnd(); } 大概思路有了,但是那位有没有比较全面的过滤函数,至少能过滤大部分的现有Sql注入攻击的应为自己写怕不够完备 用正则表达式替换sql关键字见过这种服务器组件的,该服务器所有论坛不能发表数据库类的文章 用参数化方法可有效避免SQL注入 sql注入的话可以使用存储过程其余的过滤危险字符可以使用Replace替换 /// <summary> /// 检查字符合法性 /// </summary> /// <param name="Input">被检查的字符串</param> /// <returns></returns> virtual public string CheckInjection(string Input) { string re=@"/(select)|(\-\-)|(select)|(insert)|(delete)|(count)|"+ @"(drop table)|(update)|(asc)|(mid |char)|(exec"+ ")|(\")|(:)|(\')|(or)/ix"; Regex digitregex = new Regex(re); MatchCollection mc = digitregex.Matches(Input); if ( mc.Count > 0 ) { syslog1 ("遭到SQL注入攻击,注入代码为:"+Input); return "$#$#"; } else { return Input; } } 跪求解决方案!!高手来!! asp.net 如何给后台动态生成的table设置<td>css样式 这样写得不到值啊? string wlbh = "tb" + i + "0" + (i) + ".Text"; .net 2.0都什么版本,区别? 关于URL解码的郁闷问题 数据库连接该放在哪(初学者的问题) 如何给一个存储过程赋空参数? 请大家帮忙??? 求救!简单问题!!!!!! 如何获取DataGrid的Item Id 带有“回车”“缩进”的文本内容应该用什么方法在网页上显示??(100分) 简单的上传文件的问题,请大虾关注! 超时时间已到。在操作完成之前超时时间已过或服务器未响应。急
{
return input.Replace("'","''").TrimEnd();
}
应为自己写怕不够完备
其余的过滤危险字符可以使用Replace替换
/// 检查字符合法性
/// </summary>
/// <param name="Input">被检查的字符串</param>
/// <returns></returns>
virtual public string CheckInjection(string Input)
{
string re=@"/(select)|(\-\-)|(select)|(insert)|(delete)|(count)|"+
@"(drop table)|(update)|(asc)|(mid |char)|(exec"+
")|(\")|(:)|(\')|(or)/ix";
Regex digitregex = new Regex(re);
MatchCollection mc = digitregex.Matches(Input);
if ( mc.Count > 0 )
{
syslog1 ("遭到SQL注入攻击,注入代码为:"+Input);
return "$#$#";
}
else
{
return Input;
}
}