Copied to clipboard

Flag this post as spam?

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


  • Saied 349 posts 674 karma points
    Jun 01, 2016 @ 21:55
    Saied
    0

    Request.Url.Host returns wrong host for template?

    I have a single Umbraco 7 instance that has 2 root nodes. One node points to stage.sctflash.com and the other node points to stage.bullydog.com. When I navigate to http://stage.bullydog.com/Products/accessories/podmount, the Request.Url.Host is stage.bullydog.com. Now, if I open up another tab and go to http://stage.sctflash.com/Products/accessories/podmount, the Request.Url.Host might be stage.sctflash.com, but sometimes, it just changes to stage.sctflash.com.

    The one strange thing I noticed is that if I view the accessories node in Umbraco, I noticed the parent of it is stage.bullydog.com no matter if I am on stage.sctflash.com or stage.bullydog.com

    I am using Request.Url.Host to determine as a query parameter to a database. I am basically getting the brand like this:

    if(Request.Url.Host == "stage.sctflash.com")
    return "sct";
    else
    return bullydog";
    

    So essentially if Request.Url.Host is intermittently wrong, I get the wrong query parameter.

    To see this in action, if you go to http://stage.sctflash.com/Products/accessories/podmount, you will see an SCT logo, then go to http://stage.bullydog.com/Products/accessories/podmount and you will see a Bully Dog logo. These logos are driven by Request.Url.Host. If you refresh http://stage.sctflash.com/Products/accessories/podmount, you most likely will see the Bully Dog logo now because Request.Url.Host is now stage.bullydog.com instead of stage.sctflash.com

    Since I just need to get the name of the root node. Is there a better way to do this without using Request.Url.Host? If I can get the name of the root node, this would work fine too?

  • Manish 373 posts 932 karma points
    Jun 02, 2016 @ 05:41
    Manish
    0

    Hi Saied

     var fullUrl = new Uri(Umbraco.TypedContent(uQuery.GetCurrentNode().Id).UrlAbsolute());
    var host = fullUrl.Host;
    

    Manish

  • Saied 349 posts 674 karma points
    Jun 03, 2016 @ 05:28
    Saied
    0

    The reason why accessing another website was bringing back the one websites content and the Request.Url.Host had the other websites information was because I had declared OutPutCache[Duration=60] at the top of my controller. If I waited 60 seconds and then refreshed, the correct data for each website would return. Once I removed this from the controller, everything worked as expected.

Please Sign in or register to post replies

Write your reply to:

Draft