有時候我麼您需要獲取網址,端口、路徑文件名、參數等,這裡就為大家分享一下這個函數代碼,需要的朋友可以參考下
函數1
<%function GetUrl() on Error Resume Next Dim strTempif LCase(request.ServerVariables("HTTPS")) = "off" ThenstrTemp = "http://"ElsestrTemp = "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 = strTempEnd Functionresponse.write GetUrl()%>函數2
<!--獲取當前頁面路徑--><%dim str,host,url,keyword,fullstr="http://";host = Request.ServerVariables("HTTP_HOST")url = Request.ServerVariables("PATH_INFO") '或urlkeyword = Request.ServerVariables("QUERY_STRING")if keyword <> "" thenfull = str&host&url&"?"&keywordelsefull = str&host&urlend ifsession("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進行操作。