会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
M'
.net 技术资料
博客园
首页
新随笔
联系
订阅
管理
[转]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
i
in
word.Split(
'
|
'
))
{
if
((InText.ToLower().IndexOf(i
+
"
"
)
>-
1
)
||
(InText.ToLower().IndexOf(
"
"
+
i)
>-
1
))
{
return
true
;
}
}
return
false
;
}
二,Global.asax 事件
/**/
///
<summary>
///
当有数据时交时,触发事件
///
</summary>
///
<param name="sender"></param>
///
<param name="e"></param>
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());
}
}
三,Global中的一个方法
/**/
///
<summary>
///
校验参数是否存在SQL字符
///
</summary>
///
<param name="tm"></param>
private
void
goErr(
string
tm)
{
if
(WLCW.Extend.CValidity.SqlFilter2(tm))
this
.Response.Redirect(
"
/error.html
"
);
}
//Trackback: http:
//
tb.blog.csdn.net/TrackBack.aspx?PostId=1627805
posted @
2007-06-15 09:17
M'
阅读(
1030
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告