C
C#3mo ago
Gipper

Not allowed to load local resource image error in browser console

Trying to load an image into a view with the path in the filesystem. I'm storing the images in the wwwroot folder. Is there a way around this error? I read I should set up a HTTP server on my computer but I have no idea how.
9 Replies
Angius
Angius3mo ago
How are you trying to load it?
Gipper
Gipper3mo ago
just the src attribute in the img tag
Angius
Angius3mo ago
<img src="~/images/cat.png" />?
Gipper
Gipper3mo ago
and it comes from the controller @Model.imagenmpaths[0] It's a list of strings each being a path
Angius
Angius3mo ago
What sort of a path? Absolute? Relative?
Gipper
Gipper3mo ago
it's absolute to my computer
Angius
Angius3mo ago
Well that's your issue, then wwwroot maps to / So if your images are in wwwroot/images use relative paths from /images
string[] imagePaths = [
"/images/cat.png",
"/images/dog.png",
"/images/parakeet.jpeg",
];
string[] imagePaths = [
"/images/cat.png",
"/images/dog.png",
"/images/parakeet.jpeg",
];
Gipper
Gipper3mo ago
ooooh so as far as the app is concerned wwwroot is literally the root of it's filesystem? it is in the name :picard_facepalm:
Angius
Angius3mo ago
Yep lol wwwroot is where you place your robots.txt, favicon.ico, etc So they get served from https://mywebsite.tld/favicon.ico etc
Want results from more Discord servers?
Add your server