简体   繁体   中英

Access image on IIS server from client via Url | ASP .Net

My application is an Api ASP.Net, and I save the images in the "wwwroot" folder

Content

在此处输入图像描述

When I publish my application that structure is created as well and I want to access the images through a URL

From Client Angular 2

<img  src="{{ 'http://192.168.1.20/Api/api/uploads/Koala.jpg'}} " > 
(Not Found)

I must mention, that my application is published locally, and users connected to the network must access the images

Question

How to access the image found on the IIS server with the Url? I am right? Correct me if I'm wrong Thank you all

First try to access the image url on the browser ie,

http://localhost/Api/api/uploads/Koala.jpg

If it displays the image then there is not problem with you IIS hosting.

Now try the same url from a different machine in the network ie,

http://192.168.1.20/Api/api/uploads/Koala.jpg (from a different machine)

If it does not work then make sure that you machine accepts http inbound traffic over the network.

Use tilde ~ for relative URL in paths :

<img  src="{{ '~/uploads/Koala.jpg'}} " > 

Maybe <img id="Image" runat="server" src="~/Images/img.jpg" />

Based on my understanding, you shouldn't specify the full URL in <img src="{{ }}">.

If you want to specify full URL in Src attribute, you don't need angular. You should just remove {{''}} and modify the URL to

<img  src="http://192.168.1.20/Api/api/uploads/Koala.jpg" > 

If you want to use angular2 in this case, you should just modify the URL like

 <img src="{{imageUrl}}">

Then declare the variable imageUrl in Component.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM