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;
}
查看全文
相关阅读:
Java类的静态块の二
Java类的静态块の一
Eclipse优化工具Optimizer for Eclipse
C#实现MD5WITHRSA签名
Ubuntu 初始化Root账户密码
shell连接本机虚拟机
Nodejs的Express完成安装指导
node.js之Windows 系统下设置Nodejs NPM全局路径
Unicode, UTF-8, GBK, ASCII的区别
BootstrapValidation一些tips
原文地址:https://www.cnblogs.com/weichuo/p/1205891.html
最新文章
github 学习总结
lucene 3.6.0学习总结
Activity工作流学习要点
maven 随笔
project 导出
利用itext生成pdf
firstobjet free xml的格式化
Tomcat的部署方式
java 修炼之道
打印五字棋
热门文章
RuntimeError: Broken toolchain: cannot link a simple C program
Python 金融数据分析库及相关框架
numpy unable to find vcvarsall.bat
pip windows下的引入
QT学习相关
sudo: sorry, you must have a tty to run sudo
HBase使用压缩存储(snappy)
Sqoop的使用(Mysql To HBase)
部署HBase远程访问的问题集合(Eclipse)
CDH安装
Copyright © 2011-2022 走看看