如何使用ASP而不是ASP.net获取根url?我找到了这个问题( How do I get the site root URL? )
但它与ASP.net有关。
=====================================
阿巴斯的回答为我提供了
父站点根url
但不向我提供子站点根url。
=====================================
发布于 2011-12-22 15:20:55
Classic ASP有一个包含所有服务器和环境详细信息的Request.ServerVariables集合。下面是示例.NET代码的经典ASP版本:
function getSiteRootUrl()
dim siteRootUrl, protocol, hostname, port
if Request.ServerVariables("HTTPS") = "off" then
protocol = "http"
else
protocol = "https"
end if
siteRootUrl = protocol & "://"
hostname = Request.ServerVariables("HTTP_HOST")
siteRootUrl = siteRootUrl & hostname
port = Request.ServerVariables("SERVER_PORT")
if port <> 80 and port <> 443 then
siteRootUrl = siteRootUrl & ":" & port
end if
getSiteRootUrl = siteRootUrl
end function
发布于 2011-12-23 00:06:23
这应该会让你得到你想要的。
getSiteURL()
Function getSiteURL()
dim port
dim https
dim domainname
dim filename
dim querystring
dim fullpath
dim url
port = "http"
https = lcase(request.ServerVariables("HTTPS"))
if https <> "off" then port = "https"
domainname = Request.ServerVariables("SERVER_NAME")
filename = Request.ServerVariables("SCRIPT_NAME")
querystring = Request.ServerVariables("QUERY_STRING")
fullpath = port & "://" & domainname & Request.ServerVariables("SCRIPT_NAME")
filename = right(fullpath, InStr(StrReverse(fullpath), StrReverse("/")))
url = Replace(fullpath, filename, "/")
response.write url & "<br>"
end Function
发布于 2019-11-26 19:18:37
虽然这是一个非常古老的问题,但我怀疑Hoque所要求的是页面之前的所有东西。例如,如果URL为http://www.example.com/subsite/default.asp?a=1&b=2
,则预期返回值为http://www.example.com/subsite
。
Function GetSitePath()
Dim address, port, url
address = "http://"
If LCase(Request.ServerVariables("HTTPS")) = "off" Then address = "https://"
address = address & Request.ServerVariables("SERVER_NAME")
port = Request.ServerVariables("SERVER_PORT")
If port <> 80 And port <> 443 Then address = address & ":" & port
url = Request.ServerVariables("URL")
address = address & Left(url, InstrRev(url, "/"))
GetSitePath = address
End Function
请注意,我在这里没有包含错误检查,以防止错误的URL,但如果这导致了错误,我会怀疑有一些更令人绝望的事情正在发生!
https://stackoverflow.com/questions/8600266
复制相似问题