mridula
mridula

Reputation: 3281

Images not getting loaded when Website deployed to IIS

The images used in the website are stored here (in the Images folder) -

Document Tree

And the images are referenced this way -

<img src="@Url.Content("/Images/greenDot.png")" style="margin-right: 10px;"/>

When I run the website on my local machine, all the images get loaded fine. But when I deploy it on IIS and run that website none of the images get loaded.

Errors -

Failed to load resource: the server responded with a status of 404 (Not found) http://54.234.60.214/Images/Logo_Innosolv.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://54.234.60.214/Images/Icons/bid.png

What seems to be the problem? Do I move the images to some other folder or do I change the way I reference them in the views?

Upvotes: 3

Views: 30919

Answers (3)

LockTar
LockTar

Reputation: 5465

Add the ~ sign in your path to the image.

<img src="@Url.Content("~/Images/greenDot.png")" style="margin-right: 10px;"/>

If you have authentication in your website, check if the path to the folder has public rights. You must do this in your web.config.

Upvotes: 9

mridula
mridula

Reputation: 3281

I wasn't aware that the website was deployed as a web app under an already existing website. So the images should have been fetched from

http://54.234.60.214/IBeam_2/Images/Logo_Innosolv.jpg

Instead of -

http://54.234.60.214/Images/Logo_Innosolv.jpg

So, I changed the path to

<img src="~/Images/Logo_Innosolv.jpg" style="margin-right: 10px;"/>

It is working now.

Upvotes: 2

Bhushan Firake
Bhushan Firake

Reputation: 9458

Do I change the way I reference them in the views?

Yes, off course you should change the path of the images according to your deployment directory structure. Check if you have added the correct relative or absolute path whichever be right with your website.

OR

May be you have not enabled your IIS to show images. You can do that as specified in this link

If you are loading the images with css , then you must check if that was the path problem.

Upvotes: 0

Related Questions