zoukankan      html  css  js  c++  java
  • 【转载】asp.net整站防sql注入

    一:一个方法
            /// <summary>
            ///SQL注入过滤
            /// </summary>
            /// <param name="InText">要过滤的字符串</param>
            /// <returns>如果参数存在不安全字符,则返回true</returns>
            public static bool SqlFilter2(string InText)
            {
                string word = "and|exec|insert|select|delete|update|chr|mid|master|or|truncate|char|declare|join|'";
                if (InText == null)
                    return false;
                foreach (string str_t in word.Split('|'))
                {
                    if ((InText.ToLower().IndexOf(str_t + " ") > -1) || (InText.ToLower().IndexOf(" " + str_t) > -1) || (InText.ToLower().IndexOf(str_t) > -1))
                    {
                        return true;
                    }
                }
                return false;
            }

     二:global.ascx 中的一个方法
        /// <summary>
        /// 当有数据时交时,触发事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Application_BeginRequest(Object sender, EventArgs e)
        {
            //遍历Post参数,隐藏域除外
            foreach (string str_t in this.Request.Form)
            {
                if (str_t == "__VIEWSTATE") continue;
                this.goErr(this.Request.Form[str_t].ToString());
            }
            //遍历Get参数。
            foreach (string str_t in this.Request.QueryString)
            {
                this.goErr(this.Request.QueryString[str_t].ToString());
            }
        }

    三:global.asax中的另外一方法

        /// <summary>
        /// 校验参数是否存在SQL字符
        /// </summary>
        /// <param name="tm"></param>
        private void goErr(string tm)
        {
            if (wenlong.function.func.SqlFilter2(tm))
                this.Response.Redirect("/error");
            //Response.Redirect();
        }

  • 相关阅读:
    Element-UI的表格展开的属性 type=“expand” 没有数据的则不显示展开按钮,有数据才会显示
    elementui 的 el-dialog 里面获取不到dom元素问题,设置表单滚动条到顶部问题
    el-checkbox点击事件阻止冒泡
    axios的get方法传数组参数
    elementui 的 el-data-picker 时间回填无效
    vue获取数据后给data赋值,页面不刷新的问题
    vue 项目碰到的问题
    input框只能输入汉字、数字+字母的验证
    Vue Cli3 TypeScript 搭建工程
    Form表单的主要Content-Type
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1539587.html
Copyright © 2011-2022 走看看