Why don't the images don't show up on my ASP.Net core website?

10,595

Solution 1

Make sure you allowing static files to be served:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseStaticFiles();
}

You can read more about it from here: https://docs.asp.net/en/latest/fundamentals/static-files.html

Solution 2

Make sure you put your images in correct folder. In this case it should be:

C:\{project_folder}\wwwroot\images
Share:
10,595
J.Tian
Author by

J.Tian

Updated on August 12, 2022

Comments

  • J.Tian
    J.Tian over 1 year

    I have an asp.net core web application and I want to add photos to it but when i try to debug it on IIS express, only the image icon shows up and I'm not quite sure what to do. All of my images are jpg's and are in a folder inside of the wwwroot folder. This is how I reference the photos:

    <img src="~/Images/picture.JPG" />
    

    I am not sure what to do to make the photos show up.

    • Rumpelstinsk
      Rumpelstinsk over 7 years
      Remove the ~. Use /Images/picture.jpg. / Indicates to start on the root directory: stackoverflow.com/questions/14489016/… ~ is used as alias on server-side (for Server.MapPath for example)
    • 4dgaurav
      4dgaurav over 7 years
      check that image is saved as picture.JPG or picture.jpg
  • Steve Smith
    Steve Smith over 4 years
    Why is this even an option?
  • Ateik
    Ateik over 4 years
    @SteveSmith by default you dont want to expose your server files, so you need to enable it