`
wostyh
  • 浏览: 75714 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

Global.asax 防止SQL注入

SQL 
阅读更多
    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        //遍历Post参数,隐藏域除外
        foreach (string i in this.Request.Form)
        {
            if (i == "__VIEWSTATE") continue;
            this.goErr(this.Request.Form[i].ToString());
        }
        //遍历Get参数。
        foreach (string i in this.Request.QueryString)
        {
            this.goErr(this.Request.QueryString[i].ToString());
        }
    }
 
    private void goErr(string tm)
    {
        if (SqlFilter2(tm))
        {
            Response.Write("无效的提交!");
            Response.End();
        } 
    }

    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 i in word.Split('|'))
        {
            if ((InText.ToLower().IndexOf(i + " ") > -1) || (InText.ToLower().IndexOf(" " + i) > -1))
            {
                return true;
            }
        }
        return false;
    }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics