且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何使用ASP不是ASP.net获得root网址

更新时间:2023-11-27 18:58:28

经典的ASP有一个Request.ServerVariables集合包含所有服务器和环境的详细信息。下面是这个例子.NET code的传统的ASP版本是这样的:

Classic ASP had a Request.ServerVariables collection that contained all server and environment details. Here's what the classic ASP version of the example .NET code looks like:

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