IIS 7 and Above
Problem Displaying Images on Web Page
Last post Mar 05, 2019 04:11 PM by PToomey
Mar 01, 2019 11:43 PM|PToomey|LINK
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:
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.
Mar 02, 2019 02:56 PM|lextm|LINK
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.
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.