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.Redirect("p404.html");
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;
}
本博客介绍了一个用于检测并处理恶意POST与GET请求的方法,通过遍历请求参数并利用SqlFilter2函数筛选可疑词汇,一旦检测到可疑内容,将直接跳转到错误页面。确保网站安全。
505

被折叠的 条评论
为什么被折叠?



