您的位置:首页 > 其它

过滤非法字符,防止注入式攻击等

2014-01-23 14:49 309 查看
/// <summary>
/// 过滤字符
/// </summary>
public static string Filter(string sInput)
{
if (sInput == null || sInput.Trim() == string.Empty)
return null;
string sInput1 = sInput.ToLower();
string output = sInput;
string pattern = @"*|and|exec|insert|select|delete|update|count|master|truncate|declare|char(|mid(|chr(|'";
if (Regex.Match(sInput1, Regex.Escape(pattern), RegexOptions.Compiled | RegexOptions.IgnoreCase).Success)
{
throw new Exception("字符串中含有非法字符!");
}
else
{
output = output.Replace("'", "''");
}
return output;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: