We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

Problem Displaying Images on Web PageRSS

2 replies

Last post Mar 05, 2019 04:11 PM by PToomey

  • Problem Displaying Images on Web Page

    Mar 01, 2019 11:43 PM|PToomey|LINK

    Hi Everyone,

    I'm new here. I'm having a weird problem in a new project. I'll spare you all the details and cut right to the chase.

    At this point I'm testing with an extremely simple web page. It has one div, and inside that div is an image. Here's the code:

    <!DOCTYPE html>

                      <div class="ribbon">
                               <img src="C:/tmp/db78.png">

    Here's the issue. If I put this page in a Web directory and have IIS serve it, the image gets blocked. In the Network tab of Chrome's Developer Tools, it says "blocked:other" in the status column. But if I just right click on the html file and open it with Chrome, it displays the image fine.

    I've granted Full control to Everyone and to Local System, but IIS still can't get the images.

    Does anyone have any ideas I can try.



  • Re: Problem Displaying Images on Web Page

    Mar 02, 2019 02:56 PM|lextm|LINK


    <img src="C:/tmp/db78.png">

    That line in HTML asks the web browser to open the file from drive C. That request does not go through IIS, and is usually blocked by web browser (as web security should prevent any access from web pages to local drives).


    But if I just right click on the html file and open it with Chrome, it displays the image fine.

    That's desired, because web browsers also loose security check, when they open local HTML pages (not from a web server like IIS).

    Such might be difficult for beginners to understand, but once you know more about security related topics, the intentions behind the behaviors should be clear.

    Lex Li
    Want to have a chat on the issues you meet? Book an appointment at https://buy.stripe.com/cN24ia0yi7sAdIA7sv
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Problem Displaying Images on Web Page

    Mar 05, 2019 04:11 PM|PToomey|LINK

    Thanks lextm. I got it working. What I posted was a test file, but my real project is a Razor Pages project.

    When I first set up the project, I created the path Shared\images in the Pages folder that you get as a default folder in a Razor Pages project. I put my images in there. IIS couldn't find them when I used the relative path "~Shared/images/db78.png". Yesterday I created Shared/images under wwwroot and now IIS can see the images using that same relative path. I thought relative paths in Razor Pages projects are relative to the Pages folder, but they're actually relative to wwwroot.

    Thanks for your help. After seeing your reply, I realized that my problem wasn't a security issue like I originally thought.