The code below works only if the image is located here: "E:\Test\wwwroot\thumbnails\test.png"
<div style="background-image:url('/thumbnails/test.png');height:100%;background-size: cover;"></div>
But that code can't find the image if the image is located here instead when running in Visual Studio: "E:\Test\bin\Debug\net6.0\wwwroot\thumbnails\test.png"
The problem is that I generate images and they are put inside the wwwroot/thumbnails folder but Blazor Server can't find any images there when running from Visual Studio.
Steps to reproduce:
1 Put this code in a clean Blazor Server 6.0 project: Program.cs
IWebHostEnvironment env = app.Services.GetRequiredService<IWebHostEnvironment>();
const string DEBUG_FOLDERS = @"bin\Debug\net6.0";
string generatedExample = Path.Combine(env.ContentRootPath, DEBUG_FOLDERS, "wwwroot");
File.Copy(Path.Combine(env.ContentRootPath, "wwwroot", "home.svg"), Path.Combine(generatedExample, "generatedhome.svg"), true); // This copy will simulate generated thumbnail or SQLite database.
2 Add an svg image named "home.svg" into the wwwroot folder and set it to "copy if newer"
3 Add the following code to the index page:
<h1>Image below results in 404 error.</h1>
<img src="generatedhome.svg" style="width:500px;height:500px;" />
4 Run in Visual Studio, observe the 404 error and the image not displaying.
Or this 12KB sample project: here