possibly an easy img question RRS feed

  • Question

  • User-1811674114 posted

    Putting an image on a page should be one of the easiest things to do, right? (it was easy in 1993)

    I'm baffled because I dragged the picture over to the .cshtml page and it automatically wrote it as

    <img src="C:\Users\18049\source\repos\Sherlock\img\Krebs2.jpg" />

    which works fine if I post it into a browser, but when I run the page it comes up as a broken image. 

    Friday, January 24, 2020 3:05 AM


  • User281315223 posted

    The primary issue here is that you are referencing a file from your local filesystem, which might work locally (since just a plain HTML file would know about adjecent files in your file system), but once you host it in a web server, you can think of it as in a sandbox (e.g. it can only access what the "site" has access to).

    If you wanted to resolve this, you'd need to create a folder relative to where your site is being hosted (e.g. if you root is wwwroot, then create a wwwroot/images folder and store your image in there). Then just reference your image relatively from that root (e.g. src='/images/Krebs2.jpg')

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 24, 2020 4:05 AM