Asp-Classic
獲取頁面的目前 url(使用 URL Rewrite)
我正在開發經典的 asp 應用程序。我在某些頁面上使用了 URL 重寫。
如何在經典 asp 中獲取頁面的目前 url?
範例: http ://www.site.com/page.asp —> IIS 中的 url 重寫 —> http://www.site.com/home/page
所以在這裡我想要頁面的目前網址,即http://www.site.com/home/page
請幫我。謝謝。
您可以嘗試像這樣輸出所有 ServerVariables:
for each key in Request.Servervariables Response.Write key & " = " & Request.Servervariables(key) & "<br>" next也許您尋找的 URL 已經存在。我們使用 Rewrite 模組,並且呼叫了一個 ServerVariable
HTTP_X_ORIGINAL_URL,其中包含重寫的 URL 路徑,例如您的範例中的“/home/page”。協議 (
HTTPS=ON/OFF) 和伺服器 (SERVER_NAME) 也可以在 ServerVariables 中找到。
沒有一種功能可以做到這一切。
首先,您需要獲取協議(如果它不總是 http):
Dim protocol Dim domainName Dim fileName Dim queryString Dim url protocol = "http" If lcase(request.ServerVariables("HTTPS"))<> "off" Then protocol = "https" End If現在剩下的帶有可選的查詢字元串:
domainName= Request.ServerVariables("SERVER_NAME") fileName= Request.ServerVariables("SCRIPT_NAME") queryString= Request.ServerVariables("QUERY_STRING") url = protocol & "://" & domainName & fileName If Len(queryString)<>0 Then url = url & "?" & queryString End If希望對你有效。