简体   繁体   中英

Image path with WebRootPath doesn't work. IHostingEnvironment

Hi I woudl like to ask why IHostingEnvironment address doesn't work with images.

 private readonly IHostingEnvironment env;

it is working if i am going to delete,move or anyother operation. i use this code

 Directory.CreateDirectory(env.WebRootPath + "\\ClientFolder\\" + clientNameWithNoSpace);

BUT if i use the file name for image source, i can't see the images.

Works: if @Model.ClientImageName =

"\\ClientFolder\\Paul\\ClientM.png"

Deosn't work if it is: "C:\\Users\\sari_\\source\\repos\\MnMClientEF\\MnMClientEF\\wwwroot\\ClientFolder\\Paul\\ClientM.png"

If you are doing this from teh Webserver, maybe security is getting in the way?

As Webservers usually run 24/7 and reachable from the internet, they are prime targets of hacking. So limiting their rights has become a integral part of security.

They usually each run under a seperate user. This user is given:

  • Read rights in the Programm Folder
  • Read rights in the Content Folder
  • maybe write rights in a folder below content, for stuff like temporary files. But maybe you could just solve this with a HTTP handler instead?

If you do not do that, you end up with a hacker overwriting some code that redirects users comming from google to a pornographic page (real life example).

As the relative path works but the absolute does not, this might be the cause.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM