方法一、尽量使用复杂的SQL来代替简单的一堆 SQL.
同样的事务,一个复杂的SQL完成的效率高于一堆简单SQL完成的效率。有多个查询时,要善于使用JOIN。
oRs=oConn.Execute("SELECT * from Books")
while not oRs.Eof
strSQL = "SELECT * from Authors WHERE AuthorID="&oRs("AuthorID") oRs2=oConn.Execute(strSQL)
Response.write oRs("Title")&">>"&oRs2("Name")&"<br>&q uot;
oRs.MoveNext()
wend
要比下面的代码慢:
strSQL="SELECT Books.Title,Authors.Name from Books JOIN Authors ON Authors.AuthorID=Books.AuthorID"
oRs=oConn.Execute(strSQL)
while not oRs.Eof
Response.write oRs("Title")&">>"&oRs("Name")&"<br>&qu ot;
oRs.MoveNext()
wend
方法二、尽量避免使用可更新 Recordset
oRs=oConn.Execute("SELECT * from Authors WHERE AuthorID=17",3,3)
oRs("Name")="DarkMan"
oRs.Update()
要比下面的代码慢:
strSQL = "UPDATE Authors SET Name='DarkMan' WHERE AuthorID=17"
oConn.Execute strSQL
方法三、更新数据库时,尽量采用批处 理更新
将所有的S ......
方法一、尽量使用复杂的SQL来代替简单的一堆 SQL.
同样的事务,一个复杂的SQL完成的效率高于一堆简单SQL完成的效率。有多个查询时,要善于使用JOIN。
oRs=oConn.Execute("SELECT * from Books")
while not oRs.Eof
strSQL = "SELECT * from Authors WHERE AuthorID="&oRs("AuthorID") oRs2=oConn.Execute(strSQL)
Response.write oRs("Title")&">>"&oRs2("Name")&"<br>&q uot;
oRs.MoveNext()
wend
要比下面的代码慢:
strSQL="SELECT Books.Title,Authors.Name from Books JOIN Authors ON Authors.AuthorID=Books.AuthorID"
oRs=oConn.Execute(strSQL)
while not oRs.Eof
Response.write oRs("Title")&">>"&oRs("Name")&"<br>&qu ot;
oRs.MoveNext()
wend
方法二、尽量避免使用可更新 Recordset
oRs=oConn.Execute("SELECT * from Authors WHERE AuthorID=17",3,3)
oRs("Name")="DarkMan"
oRs.Update()
要比下面的代码慢:
strSQL = "UPDATE Authors SET Name='DarkMan' WHERE AuthorID=17"
oConn.Execute strSQL
方法三、更新数据库时,尽量采用批处 理更新
将所有的S ......
<%
Dim Fy_Url,Fy_a,Fy_x,Fy_Cs(),Fy_Cl,Fy_Ts,Fy_Zx
'---定义部份 头------
Fy_Cl = 1 '处理方式:1=提示信息,2=转向页面,3=先提示再转向
Fy_Zx = "Error.Asp" '出错时转向的页面
'---定义部份 尾------
On Error Resume Next
Fy_Url=Request.ServerVariables("QUERY_STRING")
Fy_a=split(Fy_Url,"&")
redim Fy_Cs(ubound(Fy_a))
On Error Resume Next
for Fy_x=0 to ubound(Fy_a)
Fy_Cs(Fy_x) = left(Fy_a(Fy_x),instr(Fy_a(Fy_x),"=")-1)
Next
For Fy_x=0 to ubound(Fy_Cs)
If Fy_Cs(Fy_x)<>"" Then
If Instr(LCase(Request(Fy_Cs(Fy_x))),"'")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"and")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"select")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"update")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"chr")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"delete%20from")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),";")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"insert")<>0 ......
<%
Dim Fy_Url,Fy_a,Fy_x,Fy_Cs(),Fy_Cl,Fy_Ts,Fy_Zx
'---定义部份 头------
Fy_Cl = 1 '处理方式:1=提示信息,2=转向页面,3=先提示再转向
Fy_Zx = "Error.Asp" '出错时转向的页面
'---定义部份 尾------
On Error Resume Next
Fy_Url=Request.ServerVariables("QUERY_STRING")
Fy_a=split(Fy_Url,"&")
redim Fy_Cs(ubound(Fy_a))
On Error Resume Next
for Fy_x=0 to ubound(Fy_a)
Fy_Cs(Fy_x) = left(Fy_a(Fy_x),instr(Fy_a(Fy_x),"=")-1)
Next
For Fy_x=0 to ubound(Fy_Cs)
If Fy_Cs(Fy_x)<>"" Then
If Instr(LCase(Request(Fy_Cs(Fy_x))),"'")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"and")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"select")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"update")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"chr")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"delete%20from")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),";")<>0 or Instr(LCase(Request(Fy_Cs(Fy_x))),"insert")<>0 ......
现在比较流行的SQL注入工具的工作方式是通过GET和POST来完成具体的注入。我们可以将注入时所用到的一切符号过滤掉。那么我们可以通过简单的判断语句来达到目的。我们先来过滤GET吧。
代码如下:
dim sql_injdata SQL_inj SQL_Get
SQL_injdata = "’|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"
SQL_inj = split(SQL_Injdata,"|")
If Request.QueryString<>"" Then
For Each SQL_Get In Request.QueryString
For SQL_Data=0 To Ubound(SQL_inj)
if instr(Request.QueryString(SQL_Get),Sql_Inj(Sql_DATA))>0 Then
Response.Write "<Script Language=JavaScript>alert(’请不要在参数中包含非法字符尝试注入!’);history.back(-1)</Script>"
Response.end
end if
next
Next
End If
这样我们通过简单的语句我们就把一些注入所必须的语句和符号过滤掉了。非常小巧灵便,只要插到像conn.asp这样类似被调用比较广泛的页面中。同样POST我们也可以通过如下代码过滤,我们可以将两段代码整和到一起。
我们来看看代码吧:
If Request. ......
现在比较流行的SQL注入工具的工作方式是通过GET和POST来完成具体的注入。我们可以将注入时所用到的一切符号过滤掉。那么我们可以通过简单的判断语句来达到目的。我们先来过滤GET吧。
代码如下:
dim sql_injdata SQL_inj SQL_Get
SQL_injdata = "’|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"
SQL_inj = split(SQL_Injdata,"|")
If Request.QueryString<>"" Then
For Each SQL_Get In Request.QueryString
For SQL_Data=0 To Ubound(SQL_inj)
if instr(Request.QueryString(SQL_Get),Sql_Inj(Sql_DATA))>0 Then
Response.Write "<Script Language=JavaScript>alert(’请不要在参数中包含非法字符尝试注入!’);history.back(-1)</Script>"
Response.end
end if
next
Next
End If
这样我们通过简单的语句我们就把一些注入所必须的语句和符号过滤掉了。非常小巧灵便,只要插到像conn.asp这样类似被调用比较广泛的页面中。同样POST我们也可以通过如下代码过滤,我们可以将两段代码整和到一起。
我们来看看代码吧:
If Request. ......
protected void Button1_Click(object sender, EventArgs e)
{
GridViewRow gvr = (sender as Button).NamingContainer as GridViewRow; //获得容器
if(gvr != null)
{
int index = gvr.RowIndex;//index就是所点击行的行索引
}
}
// Button1 为模板列里的控件 ......
随 着网站访问量的加大,每次从数据库读取都是以效率作为代价的,很多用ACCESS作数据库的更会深有体会,静态页加在搜索时,也会被优先考虑。互联网上流 行的做法是将数据源代码写入数据库再从数据库读取生成静态面,这样无形间就加大了数据库。将现有的ASP页直接生成静态页,将会节省很多。
下面的例子是将、index.asp?id=1/index.asp?id=2/index.asp?id=3/这三个动态页面,分别生成ndex1.htm,index2.htm,index3.htm存在根目录下面:
<%
dim strUrl,Item_Classid,id,FileName,FilePath,Do_Url,Html_Temp
Html_Temp="<UL>"
For i=1 To 3
Html_Temp = Html_Temp"<LI>"
Item_Classid = i
FileName = "Index"&Item_Classid".htm"
FilePath = Server.MapPath("/")"\"
Html_Temp = Html_Temp&FilePath"</LI>"
Do_Url = "http://"
Do_Url = Do_Url&Request.ServerVariables("SERVER_NAME")"/main/index.asp"
Do_Url = Do_Url"?Item_Classid="&Item_Classid
strUrl = Do_Url
dim objXmlHttp
set objXmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
objXmlHttp.open "GET",strUrl,false
objXmlHttp.send()
Dim binFile ......
随 着网站访问量的加大,每次从数据库读取都是以效率作为代价的,很多用ACCESS作数据库的更会深有体会,静态页加在搜索时,也会被优先考虑。互联网上流 行的做法是将数据源代码写入数据库再从数据库读取生成静态面,这样无形间就加大了数据库。将现有的ASP页直接生成静态页,将会节省很多。
下面的例子是将、index.asp?id=1/index.asp?id=2/index.asp?id=3/这三个动态页面,分别生成ndex1.htm,index2.htm,index3.htm存在根目录下面:
<%
dim strUrl,Item_Classid,id,FileName,FilePath,Do_Url,Html_Temp
Html_Temp="<UL>"
For i=1 To 3
Html_Temp = Html_Temp"<LI>"
Item_Classid = i
FileName = "Index"&Item_Classid".htm"
FilePath = Server.MapPath("/")"\"
Html_Temp = Html_Temp&FilePath"</LI>"
Do_Url = "http://"
Do_Url = Do_Url&Request.ServerVariables("SERVER_NAME")"/main/index.asp"
Do_Url = Do_Url"?Item_Classid="&Item_Classid
strUrl = Do_Url
dim objXmlHttp
set objXmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
objXmlHttp.open "GET",strUrl,false
objXmlHttp.send()
Dim binFile ......
随 着网站访问量的加大,每次从数据库读取都是以效率作为代价的,很多用ACCESS作数据库的更会深有体会,静态页加在搜索时,也会被优先考虑。互联网上流 行的做法是将数据源代码写入数据库再从数据库读取生成静态面,这样无形间就加大了数据库。将现有的ASP页直接生成静态页,将会节省很多。
下面的例子是将、index.asp?id=1/index.asp?id=2/index.asp?id=3/这三个动态页面,分别生成ndex1.htm,index2.htm,index3.htm存在根目录下面:
<%
dim strUrl,Item_Classid,id,FileName,FilePath,Do_Url,Html_Temp
Html_Temp="<UL>"
For i=1 To 3
Html_Temp = Html_Temp"<LI>"
Item_Classid = i
FileName = "Index"&Item_Classid".htm"
FilePath = Server.MapPath("/")"\"
Html_Temp = Html_Temp&FilePath"</LI>"
Do_Url = "http://"
Do_Url = Do_Url&Request.ServerVariables("SERVER_NAME")"/main/index.asp"
Do_Url = Do_Url"?Item_Classid="&Item_Classid
strUrl = Do_Url
dim objXmlHttp
set objXmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
objXmlHttp.open "GET",strUrl,false
objXmlHttp.send()
Dim binFile ......
<!--#include file="conn.asp"-->
<!--#include file="inc/head.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn" lang="zh-cn" xmlns:qz="http://qzone.qq.com/">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="gb2312" />
<title>测试</title>
</head>
<body style="margin:10px;">
<form action="" method="post">
<textarea name=sql rows=5 style="width:100%" onkeypress="if(event.keyCode==10)submit.click()"><%=request("sql")%></textarea><BR>
<input type=submit id=submit style="width:20%" >
<input type=input name=pass style="width:75%" value="<%=request("pass")%>">
</form>
<%
function tip(text)
response.write(text)
end fun ......