首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

asp的url传参出现乱码,导致数据库查询失败,如何破

2013-07-20 
asp的url传参出现乱码,导致数据库查询失败,怎么破?index.asp文件中部分内容:!--#include file conn2.as

asp的url传参出现乱码,导致数据库查询失败,怎么破?
index.asp文件中部分内容:
<!--#include file ="conn2.asp"-->
<%
set rs=server.createobject("adodb.recordset")
exec="select * from ImgClass where ClassName<>'' order by Classid asc"
rs.open exec,conn,1,1
dim i,yu
i=0
%>
.....
maxlen=7 '其实是定好长度值 
ClassName=rs("ClassName") '变量赋数据记录的字段值 
If Len(ClassName)>maxlen then ClassName=left(ClassName,maxlen-1)&".." ''如果变量长度大于20--最长长度,让变量长度变成(20-2),后接... 
%>
  ......
        <td width="90" align="left"><a href="cpzs.asp?ClassName=<%=rs("ClassName")%>" title="<%=rs("ClassName")%>"><font color="#006699"><%=ClassName%></</font></a></td>

cpzs.asp中部分内容:
<!--#include file ="cp/include/connurl2.asp"-->
<%
ClassName=request("ClassName")
%>
......
      <%
ClassName=request("ClassName")
const MaxPerPage=9
   dim totalPut
   dim CurrentPage
if not isempty(request("page")) then
      currentPage=SafeRequest("page",1)
   else
      currentPage=1
   end if
  On Error Resume Next
  set rs=server.createobject("adodb.recordset")
  if ClassName="" then
     Sql = "Select * from [ImgData] order by id desc"
  Else
     Sql = "Select * from [ImgData] where ClassName='"&server.URLEncode(ClassName)&"' order by id desc"
  End IF

conn2.asp中内容:
<%
squery=lcase(Request.ServerVariables("QUERY_STRING"))
sURL=lcase(Request.ServerVariables("HTTP_HOST"))
 
SQL_injdata =":|;|>|<|--|sp_|xp_|\|dir|cmd|^|(|)|+|$|'|copy|format|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"
 
SQL_inj = split(SQL_Injdata,"|")
 
For SQL_Data=0 To Ubound(SQL_inj)
if instr(squery&sURL,Sql_Inj(Sql_DATA))>0 Then
Response.Write "SQL防注入系统"
Response.end
end if
next
%>

<%
dbpath=server.mappath("cp/include/linzi.asa")  
set conn=server.createobject("adodb.connection")  
conn.open "provider=microsoft.jet.oledb.4.0;data source=" & dbpath


%>


connurl2.asp中内容
<%
 connstr="DBQ="+server.MapPath("cp/Include/Linzi.asa")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)}"
 Set conn = Server.CreateObject("ADODB.Connection")
 conn.open ConnStr
 
 Function SafeRequest(ParaName,ParaType)
Dim ParaValue
ParaValue=Request(ParaName)
If ParaType=1 Then
If Not isNumeric(ParaValue) Then
        Response.write"<div align=center>你的操作有误!</div>"
        Response.End()
End If
Else
ParaValue=replace(ParaValue,"'","''")
End if
SafeRequest=ParaValue
End function
%>


asp菜鸟研究了好久都没解决,index.asp页面中连接cpzs.asp?ClassName=<%=rs("ClassName")%>后,就显示“SQL防注入系统”,倾全部积分,求大神搭救 asp??access asp access
[解决办法]
If Len(ClassName)>maxlen then ClassName=left(ClassName,maxlen-1)&".."
这里有问题,把后面的..去掉
[解决办法]
UserLoginIF(Server.UrlDecode(Request["UID"].ToString()), Request["PWD"].ToString());   

Encode是编码,Decode是解码.

如果还不行,
就使用post方式,或使用requestHeader,或
考虑用webservice做proxy转发.
[解决办法]
直接去掉那两点就行了
或者&".."都去掉

热点排行