zoukankan      html  css  js  c++  java
  • 格式化文本(防止SQL注入)

     /// <summary>
            /// 格式化文本(防止SQL注入)
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string Formatstr(string html)
            {
                System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[sS]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[sS]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on[sS]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[sS]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[sS]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex10 = new System.Text.RegularExpressions.Regex(@"select", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex11 = new System.Text.RegularExpressions.Regex(@"update", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex12 = new System.Text.RegularExpressions.Regex(@"delete", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                html = regex1.Replace(html, ""); //过滤<script></script>标记
                html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
                html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
                html = regex4.Replace(html, ""); //过滤iframe
                html = regex10.Replace(html, "s_elect");
                html = regex11.Replace(html, "u_pudate");
                html = regex12.Replace(html, "d_elete");
                html = html.Replace("'", "’");
                html = html.Replace(" ", " ");
                return html;
            }
    

      

  • 相关阅读:
    memcached stats 命令
    sql server 游标语法
    iis 备份
    在Win7下使用超级任务栏时,将文件夹锁定在超级任务栏打开的默认都是计算机
    微点破解90天
    win7 设置 开始菜单 程序 为经典模式
    设置 ASP.NET 存储当前应用程序的临时文件(生成的源、编译了的程序集等)的目录的物理路径。
    Java六大必须理解的问题
    Windows不能在本地计算机启动OracleDBConsoleorcl
    更改phpMyAdmin的密码
  • 原文地址:https://www.cnblogs.com/password1/p/13226608.html
Copyright © 2011-2022 走看看