- /// <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;
- }
过滤非法字符,防止注入式攻击等
最新推荐文章于 2021-05-12 17:43:09 发布