zoukankan
html css js c++ java
.net防止数据注入
把以下代码放入global.asax
protected
void
Application_BeginRequest(Object sender, EventArgs e)
{
StartProcessRequest();
}
private
void
StartProcessRequest()
{
try
{
string
sqlErrorPage
=
"
Error.aspx
"
;
//
转向的错误提示页面
if
(System.Web.HttpContext.Current.Request.QueryString
!=
null
)
{
string
url
=
Request.Url.ToString();
if
(
!
ProcessSqlStr(url))
{
Response.Redirect(sqlErrorPage);
}
}
if
(System.Web.HttpContext.Current.Request.Form
!=
null
)
{
System.Collections.Specialized.NameObjectCollectionBase.KeysCollection getkeys
=
System.Web.HttpContext.Current.Request.Form.Keys;
for
(
int
j
=
0
; j
<
getkeys.Count; j
++
)
{
if
(getkeys[j]
==
"
__VIEWSTATE
"
)
continue
;
if
(
!
ProcessSqlStr(System.Web.HttpContext.Current.Request.Form[getkeys[j]]))
{
System.Web.HttpContext.Current.Response.Redirect(sqlErrorPage);
System.Web.HttpContext.Current.Response.End();
}
}
}
}
catch
{
//
错误处理: 处理用户提交信息!
}
}
private
bool
ProcessSqlStr(
string
Str)
{
bool
ReturnValue
=
true
;
try
{
if
(Str.Trim()
!=
""
)
{
string
SqlStr
=
"
and¦exec¦insert¦select¦delete¦update¦count¦*¦chr¦mid¦master¦truncate¦char¦declare
"
;
string
[] anySqlStr
=
SqlStr.Split(
'
¦
'
);
foreach
(
string
ss
in
anySqlStr)
{
if
(Str.ToLower().IndexOf(ss)
>=
0
)
{
ReturnValue
=
false
;
break
;
}
}
}
}
catch
{
ReturnValue
=
false
;
}
return
ReturnValue;
}
查看全文
相关阅读:
CSS3盒模型display:box详解
微信公众平台开发:Web App开发入门
viewController启动方法分析
图片上加载阴影效果
属性 与成员变量的 区别与联系 及属性修饰词理解
封装 继承 多态 抽象的一点点理解
UISegmentedControl 踩坑
沙盒存储
iOS项目在非测试设备上的安装方法(项目上线前)
三方
原文地址:https://www.cnblogs.com/weichuo/p/1205891.html
最新文章
@Data 注解在实体类的使用可省去生成GET,SET方法
目前最新版本ActiveMQ 5.15.3 和JDK版本有关的问题
网络基础、多线程、ftp任务铺垫
文件上传下载、socketserver(并发)、解读socketserver源码
模拟ssh、黏包、hashlib模块
面向对象多继承(c3算法)、网络基础和编写网络相关的程序
约束、自定义异常、hashlib模块、logging日志模块
issubclass/type/isinstance、函数和方法、反射、callable、特殊成员补充
面向对象进阶二(组合补充、主动调用其他类的成员、特殊成员)
面向对象进阶一(成员(变量、方法、属性),组合或嵌套)
热门文章
面向对象初识
模块和包
手机开发必备技巧:javascript及CSS功能代码分享
jquery数组排序学习
javascript中字符串常用操作总结、JS字符串操作大全
转:Web前端,高性能优化
转:10条建议让你创建更好的jQuery插件
移动端触屏滑动事件
关于手机端视频嵌入的探索
js数组操作
Copyright © 2011-2022 走看看