Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have set up IIS in Windows 7 to run on Medium Trust, to emulate the environment where my site is hosted. According to Microsoft, in Medium Trust, you have restricted FileIOPermission. This does indeed seem to be the case because I have the following entry in my C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web_mediumtrust.config file:

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


I am trying to discover if a sub-directory exists in my application's root folder (which should be fine because I have PathDiscovery permission), but when I try the following call:

C#
DirectoryInfo logFileDirectoryInfo = new DirectoryInfo( @"\logs" );


I get a security exception, which simply says I do not have FileIOPermission.

Can anyone see what I am doing wrong? Is there perhaps another way to check if a sub-directory exists without causing this exception?

Any help or advice would be very much appreciated.

Kind wishes, Patrick
Posted

1 solution

I think you have to get the correct path first, and then check. Ive used this in the past on IIS7, and have not had any problems.

Dim DataLocation As String = httpContext.current.Server.MapPath("~/App_Data")
Dim App_Data As New IO.DirectoryInfo(DataLocation)

If Not App_Data.Exists Then
   Dim DirInfo As System.IO.DirectoryInfo
   DirInfo = System.IO.Directory.CreateDirectory(DataLocation)
   DirInfo = Nothing
End If
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900