asp 获取url函数小结
编程学习 2021-07-05 10:58www.dzhlxh.cn编程入门
asp 获取url函数小结,需要的朋友可以参考下。
方法一:简单,得不到参数,只有一个虚拟路径
GetUrl =request("url")
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
获取为:shiyan.asp
<%
dim changdu,url,ends,wurl
changdu=len(request.ServerVariables("URL"))
url=instrrev(request.ServerVariables("URL"),"/")
url=url+1
ends=changdu+1-url
wurl=mid(request.ServerVariables("URL"),url,ends)
%>
方法二:得到整个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
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
获取为:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
方法三:得到虚拟路径,得到参数
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://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
获取为:/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
方法四:只获取参数部分字符串
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
geturl=mid(geturl,instr(geturl,"?")+1)
End Function
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
获取为:dfsdfsf=dsfsdfd&aa=dddd
代码如下:
GetUrl =request("url")
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
获取为:shiyan.asp
代码如下:
<%
dim changdu,url,ends,wurl
changdu=len(request.ServerVariables("URL"))
url=instrrev(request.ServerVariables("URL"),"/")
url=url+1
ends=changdu+1-url
wurl=mid(request.ServerVariables("URL"),url,ends)
%>
方法二:得到整个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
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
获取为:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
方法三:得到虚拟路径,得到参数
代码如下:
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://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
获取为:/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
方法四:只获取参数部分字符串
代码如下:
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
geturl=mid(geturl,instr(geturl,"?")+1)
End Function
例如:http://127.0.0.1/shiyan.asp?dfsdfsf=dsfsdfd&aa=dddd
获取为:dfsdfsf=dsfsdfd&aa=dddd
上一篇:ASP 调用dll及封装dll实例
下一篇:asp 判断上传文件中是否存在危险代码