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;
}
查看全文
相关阅读:
微信开发SDK使用教程--手机微信群聊新增通知服务端
微信开发SDK使用教程--手机微信联系人信息上传服务端
微信开发SDK使用教程--手机端接收发送朋友圈任务指令后数据回传服务端
微信二次开发SDK使用教程--手机端向服务端发送回复朋友圈评论任务反馈服务端
js 自执行匿名函数(转载)
js继承中,原型属性的继承探究
搭建邮件服务器和使用压测工具的总结
window.onload和window.document.readystate的探究
读艾伦的jQuery的无new构建,疑惑分析——jquery源码学习一
WPF页面 全球化和本地化
原文地址:https://www.cnblogs.com/weichuo/p/1205891.html
最新文章
Pod资源清单
Kubernetes常见概念
Kubernetes常用命令
Kubernetest架构及其组件
Object
匿名内部类
接口的定义与使用
抽象类的定义及使用
多态
数组操作 (继承的理解)
热门文章
覆写
继承的定义与使用
内部类的定义及使用
static关键字
云控微信开发SDK使用教程--手机微信群二维码上传给服务端
云控微信开发SDK使用教程--手机微信群聊信息变更通知服务端
云控微信开发SDK使用教程--手机微信群聊删除通知服务端
云控微信开发SDK使用教程--手机微信朋友圈图片上传服务端
云控微信开发SDK使用教程--手机微信收钱任务执行结果通知服务端
云控微信开发SDK使用教程--微信联系人标签新增,修改通知服务端
Copyright © 2011-2022 走看看