zoukankan      html  css  js  c++  java
  • 过滤SQL和HTML敏感字符

    /// <summary>过滤SQL和HTML敏感字符
    ///
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public static string GetSafeSqlandHtml(string str)
    {
    if (string.IsNullOrEmpty(str))
    return string.Empty;
    str = Regex.Replace(str, @"<applet[^>]*?>.*?</applet>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<body[^>]*?>.*?</body>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<embed[^>]*?>.*?</embed>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<frame[^>]*?>.*?</frame>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<frameset[^>]*?>.*?</frameset>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<html[^>]*?>.*?</html>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<iframe[^>]*?>.*?</iframe>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<style[^>]*?>.*?</style>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<layer[^>]*?>.*?</layer>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<link[^>]*?>.*?</link>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<ilayer[^>]*?>.*?</ilayer>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<meta[^>]*?>.*?</meta>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<object[^>]*?>.*?</object>", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"-->", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @"<!--.*", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, "eXeC", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, "VaRcHaR", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, "dEcLaRe", "", RegexOptions.IgnoreCase);
    str = Regex.Replace(str, @";", string.Empty);
    str = Regex.Replace(str, @"'", string.Empty);
    str = Regex.Replace(str, @"&", string.Empty);
    str = Regex.Replace(str, @"%20", string.Empty);
    str = Regex.Replace(str, @"--", string.Empty);
    //str = Regex.Replace(str, @"==", string.Empty);
    str = Regex.Replace(str, @"<", string.Empty);
    str = Regex.Replace(str, @">", string.Empty);

    return str;
    }

  • 相关阅读:
    编码上的小改进
    自定义HttpFilter模块完善
    Log4Net日志分类和自动维护
    也来写写基于单表的Orm(使用Dapper)
    要知道的DbProviderFactory
    仿Orm 自动生成分页SQL
    【问题帖】压缩图片大小至指定Kb以下
    [leetcode]Find Minimum in Rotated Sorted Array
    [leetcode]Maximum Product Subarray
    join
  • 原文地址:https://www.cnblogs.com/pangzhixing/p/6596420.html
Copyright © 2011-2022 走看看