简体   繁体   中英

asp.net Images not loading after publishing

My images won't load after I publish my application. They do load when I'm debugging. Any idea what can cause this problem?

<a class="navbar-brand" href="@Url.Action("SearchQuery", "Search")"><img id="logo" src="~/Images/Logo.png"/></a>

Steps to add images to be published:

1) Right click the images folder and select "Include In Project"

包含在项目中

2) Now you should see Build Action: Content on the properties for the images.

在此处输入图像描述

Try Url.Content on your src attribute:

src="@Url.Content("~/Images/Logo.png")"

Are you sure you have set the Image folder to be deployed along with your other files (Folder --> Properties --> Build Action)?

For further information please take a look at: https://msdn.microsoft.com/en-us/library/ee942158(v=vs.110).aspx#Anchor_1

Please check your publish code because of after your publish this image not appear in particular folder. may be issue of publish.

Maybe you do add image to your development folder (via explorer etc) but not to your project. If an image file is not included in project, this will happen.

If this is the case; please check if you can see logo.png under Images folder with an image icon in Visual Studio's solution explorer. If it's not there try checking "Show All Files" in solution explorer's toolbar. Then try right click -> Include In Project. After that, publish will copy the file to output folder.

THIS may help.

I had the same problem - image loading at debugging in VS/IIS, but not after deployment on another computer.

Did all that was advised here and elsewhere. After hours of searching and not finding any answers, I came across the most fundamental solution.

Turned out, it was my fault, being too hasty with the windows features setup.

You need to turn on static content for WWW services, as it is described in the linked answer, and as was probably mentioned in every tutorial ever, which obviously I missed.

Hope that helps someone.

When a image wont load, always be sure to inspect the network tab within the dev tools. I had a problem where images with a specific folder wouldn't load after upload. Turned out that I had adblock installed on my pc and the folder was named Adverts. duh!

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