当前位置: 首页 > 图文教程 > 网络编程 > ASP > [原创]asp获取URL参数的几种方法分析总结

ASP
自动采集程序
一个防止被采集的方法
帮你打造属于自己的搜索引擎---百度篇
实例讲解ASP实现抓取网上房产信息
XMLHTTP批量抓取远程资料
XMLHTTP抓取远程数据的后期处理
用XMLHTTP很好的一个例子
采集原理---采集技术篇---XMLHTTP
小偷,采集程序常用函数
服务器常用组件
如何在不支持数据库的asp主页上运用ado
做文章系统时, 如何让长篇的文章自动换行
Access中使用Create Procedure创建存储过程
ASP中的时间函数大全 时间操作函数
无组件实现文件上传/下载
asp网页邮箱访问
不用模板只用ASP+FSO生成静态HTML页的一个方法
用sql设置access的默认值
Asp事务处理
统计有多少行JS代码和ASP代码

ASP 中的 [原创]asp获取URL参数的几种方法分析总结


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 128 ::
收藏到网摘: n/a

asp获取当前网址,或获取当前页面的所以参数 需要用到这个功能,没怎么测试呢,测试后给具体代码
假如地址是:
http://dxy.com:8082/test/geturl.asp?Param-VR52tmx3syn03777.html
方法一:简单,得不到参数,只有一个虚拟路径
复制代码 代码如下:

GetUrl =request("url") '这个因为我们没有url=什么字样所以直接pass掉

方法二:得到整个URL,得到参数
复制代码 代码如下:

'得到当前页面的地址
Function GetUrl()
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "http://"
Else
strTemp = "https://"
End If
strTemp = strTemp & Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT")
strTemp = strTemp & Request.ServerVariables("URL")
If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(Request.QueryString)
GetUrl = strTemp
End Function

经测试这个代码得到的路径为:
/test/geturl.asp?Param-VR52tmx3syn03777.html=
方法二:得到虚拟路径,得到参数
复制代码 代码如下:

Private Function GetUrl()
Dim ScriptAddress,M_ItemUrl,M_item
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME")) '取得当前地址
M_ItemUrl = ""
If (Request.QueryString <> "") Then
ScriptAddress = ScriptAddress & "?"
For Each M_item In Request.QueryString
If M_item = "page_num" Then Exit for '此处的作用就是过滤掉Page_num这个页次的参数(该参数是在page_turn.asp中自行设置的,根据个人设定而变),否则每次翻页都会叠加这个参数,虽然不影响功能,但总归不太好吧~~
If InStr(page,M_Item)=0 Then
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&""))
else
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&"
End If
Next
Else
ScriptAddress = ScriptAddress & "?"
end if
GetUrl = ScriptAddress & M_ItemUrl
End Function

上面的代码得到的地址为
http://dxy.com:8082/test/geturl.asp?Param-VR52tmx3syn03777.html
基本上差不多
如果只是为了得到?号后面的东西,我们可以用下面的代码
复制代码 代码如下:

response.write replace(request.querystring,".html","")

得到的就是Param-VR52tmx3syn03777是不是满足了我们的需要了呢
PS:上面的所有情况只是针对纯asp,如果结合urlrewrite的话,功能会有所增强,搜索的友好型,也会加强