Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mike Manusama 45 posts 195 karma points
    May 26, 2022 @ 01:52
    Mike Manusama
    0

    Getting the absolute URL of the hostname or the root URL

    I have a site with a few subdomains on it that use all use the same navigation and footer (via partial macros)

    Content tree
    - www.mainsite.com
    - subdomain1.mainsite.com
    - subdomain2.mainsite.com

    Is there a way to pull in the absolute URL of the "www.mainsite.com" without actually typing that in to all of the href's for the nav and footer? I assumed there would be an easy way to do this, and I have tried a few solutions - but none have worked.

    Here is what HASN'T worked so far:

    @Request.Url.ToString()
    @Request.RawUrl.ToString()

    @Request.UserHostName
    @Request.Url.AbsoluteUri
    @Request.Url.AbsolutePath
    @Request.Url.Host
    @Request.Url.Scheme
    @Request.Url.Authority
    @Request.Url.AbsolutePath

    Any idea what the issue might be?

  • Darion Richards 1 post 21 karma points
    Nov 09, 2022 @ 12:29
    Darion Richards
    0

    Hi Mike!

    After experiencing a similar problem and coming across your question, I have found a solution.

    In order to pull the current absolute URL you can create a string template which would dynamically render the absolute URL depending on the current path.

    string requestUrl = $"{Context.Request.Scheme}://{Context.Request.Host.ToString()}{Context.Request.PathBase}{Context.Request.Path}";
    

    Then pass the variable to where you wish to use the absolute URL.

    Hope it helps!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies