How to upload a file from a bin folder in ASP.NET in a trust tool

I need to load an xML file from a bin folder in ASP.NET (MVC, not what it will take). I can not get the path to the bin folder or upload the file otherwise. I need to submit the following method:

using(var file = System.IO.File.OpenRead(/* something */))
{

}
+3
source share
2 answers

okay .. under average trust, all I could do, and not have it blown up on my face, was this:

var binFolderPath = Server.MapPath("bin");

then

Path.Combine(binFolderPath, "myConfigFile.xml");
+4
source

For some reason, it would seem that by default your IIS does not allow access to your bin folder. This is probably inherited from the parent site above your virtual directory. Regardless, see this link for FileIO with medium trust:

http://msdn.microsoft.com/en-us/library/ms998341

, web.config, AppDir, / .

<IPermission
  class="FileIOPermission"
  version="1"
  Read="$AppDir$"
  Write="$AppDir$"
  Append="$AppDir$"
  PathDiscovery="$AppDir$"
/>
+4

Source: https://habr.com/ru/post/1747446/


All Articles