我正在使用經典的asp應用程序。 我在一些頁面上使用URL重寫。獲取頁面的當前網址(使用URL Rewrite)
我如何獲得經典asp頁面的當前網址?
例子: http://www.site.com/page.asp --->在IIS URL重寫--->http://www.site.com/home/page
所以在這裏,我想這是http://www.site.com/home/page
請幫我頁面的當前的URL。 謝謝。
我正在使用經典的asp應用程序。 我在一些頁面上使用URL重寫。獲取頁面的當前網址(使用URL Rewrite)
我如何獲得經典asp頁面的當前網址?
例子: http://www.site.com/page.asp --->在IIS URL重寫--->http://www.site.com/home/page
所以在這裏,我想這是http://www.site.com/home/page
請幫我頁面的當前的URL。 謝謝。
你可以試着輸出所有ServerVariables像這樣:
for each key in Request.Servervariables
Response.Write key & " = " & Request.Servervariables(key) & "<br>"
next
也許你所尋求的網址已經存在。我們使用Rewrite模塊,並且有一個名爲HTTP_X_ORIGINAL_URL
的ServerVariable包含重寫的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
希望它爲你工作。
如果使用URL重寫,URL數據只能通過這種方式來獲得:
Request.ServerVariables( 「HTTP_X_ORIGINAL_URL」)
例
Dim domainName, urlParam
domainName = Request.ServerVariables("SERVER_NAME")
urlParam = Request.ServerVariables("HTTP_X_ORIGINAL_URL")
response.write(domainName & urlParam)
你能不能用Request.ServerVariables(「server_name」)和Request.ServerVariables(「url」)''讀取它?不知道這是否也適用於重寫的URL ... – 2013-03-13 20:02:45
否Request.ServerVariables(「server_name」)= www.site.com和Request.ServerVariables(「url」)= page.asp – Maddy 2013-03-13 20:06:32
您可以標記任何這些答案如果他們對你有幫助?如果沒有,請讓我們知道,以便我們可以找到解決方案。 – Konrad 2013-03-16 01:49:13