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;
}
查看全文
相关阅读:
理解HTTP幂等性
企业技术树
数据库MySQL-Oracle-DB2-SQLServer分页查询
Redis安装教程
Redis VS Memcached
Redis简介
Redis系列文章导读
坐标轴
图例
画网格
原文地址:https://www.cnblogs.com/weichuo/p/1205891.html
最新文章
数据库使用B+树原理
先操作缓存还是数据库
缓存使用注意点
在POM配置Maven plugin提示错误“Plugin execution not covered by lifecycle configuration”的解决方案
爬虫3_python2
爬虫2_python2
爬虫1_python2
css
HTML_6 (表单应用)
HTML_5 (1 2 3的代码总结)
热门文章
HTML_4
HTML_3
HTML_2
HTML_1
第三篇:GPU 并行编程的运算架构
第二篇:从 GPU 的角度理解并行计算
第一篇:容易遗忘的“枚举”
HashMap vs Hashtable
数据库三范式
练习葵花宝典
Copyright © 2011-2022 走看看