How do I get root url using ASP not

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

but it is related to


Abbas's answer provide me the

parent site root url

but does not provide me the subsite root url


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"
        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

How do I get root url using ASP not - asp-classic - html, Here's what the classic ASP version of the example .NET code looks like: function getSiteRootUrl() dim siteRootUrl, protocol, hostname, port if Request. How to Get the Base URL in ASP.NET: Conclusion. We’ve looked at a number of different ways to get the base URL in ASP.NET and .NET Core. There are a lot of options (almost too many), but I find the ones discussed here to be simple enough to get the job done.

This should get you what you want.


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 

How to get the root URL of my project?, Because the port number may change sometime, so I do not want to hard code this part. Anybody knows how to do it in c# code? thanks a lot,. Getting the Web Root Path and the Content Root Path in ASP.NET Core May 22, 2016. In ASP.NET Core, the physical paths to both the content root and the web root directories can be retrieved via the IWebHostEnvironment service. Here's an example of a HomeController that uses constructor dependency injection to get an IWebHostEnvironment:

Though this is a very old question, I suspect what Hoque is asking for is everything before the page. For instance, if the URL is, the expected return value would be

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

Note that I've included no error checking here, to prevent bad URLs, but if this causes an error I would suspect there's something a little more desperate going on!

ASP.NET Core Blazor routing, Learn how to route requests and how to use the NavLink component ASP.NET Core endpoint routing integration. Blazor Server is integrated into ASP. For information on configuring MapFallbackToPage for non-root URL� In an ASP.NET application the framework controls recognise a tilde ('~') as a shortcut to the root of the application's virtual directory. So the framework will expand a tilde to the value of HttpRuntime.AppDomainAppVirtualPath.

HttpContext.RewritePath Method (System.Web), The path parameter is not in the current application's root directory. ASP.NET Routing � Walkthrough: Using ASP.NET Routing in a Web Forms Application� When an HTTP GET request is sent to the root URL /: The request delegate shown executes. Hello World! is written to the HTTP response. By default, the root URL / is https://localhost:5001/. If the request method is not GET or the root URL is not /, no route matches and an HTTP 404 is returned. Endpoint. The MapGet method is used to define an

Dealing with Application Base URLs and Razor link generation , I'm also moving from an ASP.NET 4 (was ASP.NET 2 until recently) site to ASP. of the generated URL that's sent to and from the browser, not about any Root);. string path = rootUri.AbsolutePath;. //Deal with path base and� ASP.NET Core controllers use the Routing middleware to match the URLs of incoming requests and map them to actions. Routes templates: Are defined in startup code or attributes. Describe how URL paths are matched to actions. Are used to generate URLs for links. The generated links are typically returned in responses.

How to Get the Base URL in ASP.NET, Learn how to get the base URL in ASP.NET. It doesn't have to be as hard as it looks! You can also get the root path by accessing the. Uri however, and not something you'd want to use over and over again in your markup. If the data dropped contains a UniformResourceLocator format, you can get the entire URL from that, for example: Private Sub Form1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop If e.Data.GetDataPresent("UniformResourceLocator") Then Dim URL As String = New IO.StreamReader(CType(e.Data.GetData("UniformResourceLocator"), IO.MemoryStream)).ReadToEnd End If End Sub It first checks to see if a

  • possible duplicate of ResolveUrl/Url.Content Equivalent in Classic Asp
  • If my site url is parentSite/subsite/default.asp, will the above return parentSite/subsite as root url?
  • I have translated the .NET code to Classic ASP so it will do what the code in your example was doing. If your site is not using SSL and uses port 80, The code above will show: http:// parentSite/subsite. The best way to understand it is to run it and play around with it. It's quite simple and if you run into difficulties you can post them here.
  • I have tested and it does not go to subsite
  • As I said, I translated the example. From your question, it's not clear what you require. There is not direct way to get what you need. Request.ServerVariables("URL") and Request.ServerVariables("PATH_INFO") contain the path of the script including subfolders. By parsing these variables, you should be able to get what you need.
  • @Abbas: Its close, there is an assumption that HTTPS is not being run through port 80 and HTTP is not being run through port 443 (it would be mad to do that but technically it is possible).
  • No, it does not. It provides the part of the url from where I have call the function. For example, if I call the function from this page parentSite/childsite/Folder/Default.asp it returns parentSite/childsite/Folder
  • so then I guess I'm not sure what you want? What I posted will return the path to the page your on. Is the function on a page different than you want to display and where is the page that is you will be getting the URL on? You may have to pass the information to the function in order for it to be used.
  • would like to return parentSite/childSite as the childsite's root url
  • if the page that will create the URL is under folder then you'll either need to parse out the URL you want or pass it to the function from the calling page. Using what I have posted you could parse it out if you know how far back up the chain you want.
  • As I need the root url of the childsite/parentsite, if it is programaticlly difficult, it might be better to keep it as a constant. By the way, @Abbas's solution returns the root url of parent site but not the childsite.