如何使用ASP而不是ASP.net获取根URL

Hoq*_*que 6 asp-classic

如何使用ASP而不是ASP.net获取根URL?我发现了这个问题( 如何获取站点根URL? )

但它与ASP.net有关.

=====================================

阿巴斯的答案为我提供了答案

父站点根URL

但是没有为我提供子网站根网址

=====================================

Abb*_*bas 13

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
Run Code Online (Sandbox Code Playgroud)