C
C#2y ago
shack

✅ aspnet core not recognizing images

I made a project in jb rider, and for some reason imgs in html are getting a 404. I had this problem with css and js scripts before, but I fixed it by including a separate get method for each of them. When I tried making one for the img, it only removed the console error. Nothing was found in Chrome Sources, and when I tried to download the image chrome had, I couldn't open it. Startup.cs
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync(await File.ReadAllTextAsync("wwwroot/html/index.html"));
});
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync(await File.ReadAllTextAsync("wwwroot/html/index.html"));
});
index.html
<img alt="img" src="/img.jpeg">
<img alt="img" src="/img.jpeg">
2 Replies
Angius
Angius2y ago
The image is in /html/img.jpeg not /img.jpeg Assuming the file serving middleware has been set up, the root for static file location is wwwroot
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?