有时候我么您需要获取网址,端口、路径文件名、参数等,这里就为大家分享一下这个函数代码,需要的朋友可以参考下
函数1
<%
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
response.write geturl()
%>
函数2
<!--获取当前页面路径-->
<%
dim str,host,url,keyword,full
str="http://";
host = request.servervariables("http_host")
url = request.servervariables("path_info") '或url
keyword = request.servervariables("query_string")
if keyword <> "" then
full = str&host&url&"?"&keyword
else
full = str&host&url
end if
session("url")=full
%>
使用的话肯定选择第一个,支持https的判断。
如果是通过404页面除非,这个是获取不到的,需要结合js来实现
例如:
js页面
<script>
var pathname = window.location.pathname;
location.replace("/do.asp?p="+pathname);
</script>
将路径传参给do.asp进行处理
strpath=request("p")
即可获取404之前的页面,然后进行执行操作即可,注意目录权限。也可以放到404中处罚iframe进行操作。
发表评论