How do I load a file from bin folder in ASP.NET in medium trust
Asked Answered
T

2

5

I need to load an xML file from the bin folder in ASP.NET (MVC, not that it would count). I can't get the bin folder path nor load the file otherwise.. I need to feed the following method :

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

}
Tendance answered 27/5, 2010 at 22:34 Comment(0)
T
7

well.. under medium trust all I could do and not have it blown in my face was this :

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

then

Path.Combine(binFolderPath, "myConfigFile.xml");
Tendance answered 1/6, 2010 at 19:51 Comment(0)
E
4

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

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

You likely need to add a section to your web.config to provide specific access to your AppDir to override the setting from the parent site/virtual directory.

<IPermission
  class="FileIOPermission"
  version="1"
  Read="$AppDir$"
  Write="$AppDir$"
  Append="$AppDir$"
  PathDiscovery="$AppDir$"
/>
Elanaeland answered 28/5, 2010 at 1:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.