C
C#5mo 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
Angius5mo ago
How are you trying to load it?
Gipper
GipperOP5mo ago
just the src attribute in the img tag
Angius
Angius5mo ago
<img src="~/images/cat.png" />?
Gipper
GipperOP5mo ago
and it comes from the controller @Model.imagenmpaths[0] It's a list of strings each being a path
Angius
Angius5mo ago
What sort of a path? Absolute? Relative?
Gipper
GipperOP5mo ago
it's absolute to my computer
Angius
Angius5mo 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
GipperOP5mo 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
Angius5mo 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