Application_BeginRequest事件過濾惡意提交


Global.asax

 

 1 protected void Application_BeginRequest(object sender, EventArgs e)
 2     {
 3         //遍歷Post參數,隱藏域除外 
 4         foreach (string i in this.Request.Form)
 5         {
 6             if (i == "__VIEWSTATE") continue;
 7             this.goErr(this.Request.Form[i].ToString());
 8         }
 9         //遍歷Get參數。 
10         foreach (string i in this.Request.QueryString)
11         {
12             this.goErr(this.Request.QueryString[i].ToString());
13         }
14     }
15     private void goErr(string tm)
16     {
17         if (SqlFilter2(tm))
18         {
19             Response.Redirect("p404.html");
20             Response.End();
21         }
22     }
23     public static bool SqlFilter2(string InText)
24     {
25         string word = "and|exec|insert|select|delete|update|chr|mid|master|or|truncate|char|declare|join";
26         if (InText == null)
27             return false;
28         foreach (string i in word.Split('|'))
29         {
30             if ((InText.ToLower().IndexOf(i + " ") > -1) || (InText.ToLower().IndexOf(" " + i) > -1))
31             {
32                 return true;
33             }
34         }
35         return false;
36     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM