Last post Jan 30, 2021 10:35 AM by theturkeytickler
Jan 30, 2021 09:19 AM|theturkeytickler|LINK
Hi all - I am literally tearing my hair out with this! I have a web app, its a simple ASP.NET Core Web App... created in VS 2019.
In the project folder I have created a folder called images, and placed an image called Logo.jpg into that folder. I want to display the image on a web page. I have edited the default Index.cshtml to create an IMG tag referencing this image.
I have tried everything I can think of to make this image appear in the Index.cshtml output but everything i try ends up with the broken image (404) icon. Heres the source for Index.cshtml;
Obviously, what you can see is a load of different attempts, different syntaxes, differing relative paths to try to get this image to show but nothing works.
I have set the properties of the image itself to be Build Action: Content and Copy to Output Directory: Copy Always, and the image is present in the <project>\bin\Debug\netcoreapp3.1\images folder
I am obviously doing something fundamentally wrong but for the life of me I can't work out what it is!
Could someone please point me in the right direction with this?
Many thanks in advance
Jan 30, 2021 09:20 AM|theturkeytickler|LINK
Apologies - that source got mangled by the looks of it....
Jan 30, 2021 10:05 AM|PatriceSc|LINK
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-5.0, ie in short ASP.NET Core keeps files published directly on your site in their own sub folder (and you have to add the middleware serving those files)
Your images folder is under the wwwroot folder on the published site? If in bout I would start by tyyping the exact url in my browser address bar to see of the problem is that the generated url is wrong or that for now this file is just not served at all
by the site.
Jan 30, 2021 10:35 AM|theturkeytickler|LINK
Thank you thank you thank you! I moved the images folder to wwwroot and it works perfectly!!
Thank you so much!