locked
Browser creates inconsistent paths for an image URL. RRS feed

  • Question

  • User-1078583883 posted
     
    I have markup like this:
    <img src="../Content/images/default.jpg"/>
    On our dev URL, the browser sends a request to the server like this:
    https://devSite.com/Content/images/default.jpg
    On our prod URL, the browser sends this (it adds the 'Home' segment)
    https://prodSite.com/Home/Content/images/default.jpg
    where 'Home' is the HomeController. Why the discrepancy in segements?
     
     
    I've been looking at this for hours and still have no clue.

    Wednesday, May 26, 2021 10:57 AM

Answers

  • User475983607 posted

    The code has a reference bug.  Use a relative reference not an absolute reference.  

    /Content/images/default.jpg

    https://www.w3schools.com/html/html_filepaths.asp

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 26, 2021 11:01 AM
  • User753101303 posted

    Hi,

    More likely it depends if you are using site.com, site.com/home or site.com/home/index in the browser address bar.

    Depenign on your version you also have the ~ that is processed server side and is the web application  root. It can be usefull if you app is made available under a root web site ie somethung such as site.com/myapp/.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 26, 2021 12:06 PM
  • User475983607 posted

    I'm not trying to be difficult - it's just that my boss will demand to know why the same code works fine on dev and not on prod. He's generally unhappy when I can't explain such discrepancies because he fears it means we don't know the root of the issue. 

    You are assuming this is a browser issue which is stopping you from realizing the bug is in your general design.  The usual cause of this bug is the dev environment root host is different than the production host.  In dev the host might be localhost:xxxx or localhost/appname depending on your dev host.  Production is usually https://www.domain.com  but it could be  https://www.domain.com/appname.  

    Again, you'll want to use relative references.  Please read the link in my first post.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 26, 2021 12:59 PM
  • User753101303 posted

    https://devSite.com/ works but what happens with https://devSite.com/Home or https://devSite.com/Home/Index ?

    I don't expect https://prodSite.com/ to be driecred automatically to https://prodSite.com/Home some likely you have a redidrecrion rule somewhere. What if using  https://prodSite.com/Home/Home or https://prodSite.com/Home/Index ? If Home/Gome works could ie be that the site was installed in a Home applicarion under the website root ???

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 26, 2021 2:46 PM

All replies

  • User475983607 posted

    The code has a reference bug.  Use a relative reference not an absolute reference.  

    /Content/images/default.jpg

    https://www.w3schools.com/html/html_filepaths.asp

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 26, 2021 11:01 AM
  • User-1078583883 posted

    Yes I came to that conclusion myself. But really my question here is why the browser is forming two different URLs for the same markup.

    Wednesday, May 26, 2021 11:48 AM
  • User753101303 posted

    Hi,

    More likely it depends if you are using site.com, site.com/home or site.com/home/index in the browser address bar.

    Depenign on your version you also have the ~ that is processed server side and is the web application  root. It can be usefull if you app is made available under a root web site ie somethung such as site.com/myapp/.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 26, 2021 12:06 PM
  • User475983607 posted

    Yes I came to that conclusion myself. But really my question here is why the browser is forming two different URLs for the same markup.

    The browser is working as expected.  Your code has the bug.  As suggested above, you might need to use the "~/" depending on how your markup is designed which we cannot see.

    Wednesday, May 26, 2021 12:15 PM
  • User-1078583883 posted

    The URL placed in the address bar is the same - the only difference is the host (prod versus dev). That's why I'm confused as to why the browser is sending two different segment-constructs to the server.

    Wednesday, May 26, 2021 12:21 PM
  • User-1078583883 posted

    The markup is created clientside in my case, so I don't think the tilde will work. 

    Wednesday, May 26, 2021 12:26 PM
  • User-1078583883 posted

    I'm not trying to be difficult - it's just that my boss will demand to know why the same code works fine on dev and not on prod. He's generally unhappy when I can't explain such discrepancies because he fears it means we don't know the root of the issue. 

    Wednesday, May 26, 2021 12:29 PM
  • User475983607 posted

    I'm not trying to be difficult - it's just that my boss will demand to know why the same code works fine on dev and not on prod. He's generally unhappy when I can't explain such discrepancies because he fears it means we don't know the root of the issue. 

    You are assuming this is a browser issue which is stopping you from realizing the bug is in your general design.  The usual cause of this bug is the dev environment root host is different than the production host.  In dev the host might be localhost:xxxx or localhost/appname depending on your dev host.  Production is usually https://www.domain.com  but it could be  https://www.domain.com/appname.  

    Again, you'll want to use relative references.  Please read the link in my first post.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 26, 2021 12:59 PM
  • User753101303 posted

    https://devSite.com/ works but what happens with https://devSite.com/Home or https://devSite.com/Home/Index ?

    I don't expect https://prodSite.com/ to be driecred automatically to https://prodSite.com/Home some likely you have a redidrecrion rule somewhere. What if using  https://prodSite.com/Home/Home or https://prodSite.com/Home/Index ? If Home/Gome works could ie be that the site was installed in a Home applicarion under the website root ???

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 26, 2021 2:46 PM
  • User-1078583883 posted

    This is not localhost, not even for the dev site.  It's on azureWebsites.net (AppServices) and our setup is always the same as far as I can see. We don't use anything complex like subdomains, in fact it's not even a custom domain.  It's just devSite.AzureWebsites.Net and prodSite.AzureWebsites.Net

    Wednesday, May 26, 2021 5:51 PM
  • User-1078583883 posted

    I gave up on this. I'll never understand the discrepancy but I do agree that removing the 2 dots is the fix. Thanks so much everyone for the quick help.

    Wednesday, May 26, 2021 7:46 PM