Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get root url using ASP not ASP.net

Tags:

asp-classic

How do I get root url using ASP not ASP.net? I have found this question ( How do I get the site root URL? )

but it is related to ASP.net.

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

Abbas's answer provide me the

parent site root url

but does not provide me the subsite root url

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

like image 403
Nazmul Avatar asked Dec 22 '11 06:12

Nazmul


People also ask

How do I find the root URL?

You can determine your server's root URL by browsing to a page on your website and observing the address in the location/address entry field of the browser. The root URL is the section between the colon-slash-slash (://) and the next slash (/), omitting any port number (:portno).

How do I find the base URL of a controller?

How to Get the Base URL in an MVC Controller. Here's a simple one-liner to get the job done. var baseUrl = string. Format(“{0}://{1}{2}”, Request.

What is application root URL?

It represents an available URL namespace (for example, http://example). The Web application root is the folder on your hard disk that corresponds to this URL namespace. For example, placing a file called file. htm in the Web application root folder results in an available URL at http://example/file.htm.

What is URL content?

A URL (Uniform Resource Locator) or webpage address, is a reference to a web resource that specifies its exact location online (within a computer network). A content URL refers to a webpage address that specifically relates to certain content on the internet, such as an image or a video file.


1 Answers

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
like image 133
Abbas Avatar answered Nov 07 '22 10:11

Abbas