0

This is a Blazor server rendered project, in .NET 9, published on IIS.

I'm trying to pull paths to images and other files from the database that are currently stored in the format:

~/TopicDirectory/Images/ImageFileName.jpg

When put as the source for an image tag, it's not displaying (and going to the path 404s).

I figured out I needed to do a substring to remove the leading ~/

<img src="@TopicItem.Image.Substring(2)">

If I add the source image to the project before publishing it, in the same directory structure, the image displays. E.g. wwwroot/TopicDirectory/Images/ImageFileName.jpg.

However, files will need to be added to that directory after the publishing of the new website so I need it to be able to read things that aren't published with the project.

I've ensured static files are enabled in IIS as I read that could be a factor.

I've tried adding just the TopicName\Images folder to the project structure and adding the images/other files after and it doesn't load them.

I've tried accessing the path pulled from the DB without the file being contained in the project and it fails.

Adding the file to the project before publishing it with all other aspects the same succeeds.

Adding additional files to the directory created in the fashion fails.

I've ensured the application identity user is the one accessing the files using procmon and that it has permissions to that directory.

1 Answer 1

0

Found the answer here: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/map-static-files?view=aspnetcore-9.0

I needed to use UseStaticFiles() in my program.cs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.