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;
    }

  • 相关阅读:
    让程序的性能提升10倍
    以正确的姿势实现一棵JavaScript菜单树
    利用php数组函数进行函数式编程
    yum安装下的nginx,如何添加模块,和添加第三方模块
    前端面试题 vue
    前端常用面试题目及答案-HTML&CSS篇
    使用after伪类,配合IE的zoom或者overflow清除浮动
    函数式编程
    在CentOS 7上安装Node.js
    node中__dirname、__filename、process.cwd()、process.chdir()表示的路径
  • 原文地址:https://www.cnblogs.com/pangzhixing/p/6596420.html
Copyright © 2011-2022 走看看