473,322 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Help - How am I misusing FileIOPermission?

Hi,
I'm trying to test permission to access the file system, using
FileIOPermission, but can't seem to get it to work.

See my sample app below, for an app that tries to demand a permission
to read a specified path, and then calls Directory.GetFiles on that
path.

The Demands on FileIOPermissions (I tried 3 variations) all work, and
then when I call Directory.GetFiles an exception is thrown... saying
'request for FileIOPermission failed'!.

(NB: when run in full trust (local path) the Directory.GetFiles runs
successfully).

Can anyone explain how to check for permissions?
Here is the output of the app, when run from an intranet path, with
intranet security level set to 'one step down from full trust':
-------------------------------------------
..
..
..
System.Security.SecurityException: Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Cultur
e=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Obj ect demand,
StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.Directory.InternalGetFileDirectoryNames( String path,
String userPathOriginal, String searchPattern, Boolean includeFiles,
Boolean incl
udeDirs, SearchOption searchOption)
at System.IO.Directory.GetFiles(String path, String searchPattern,
SearchOption searchOption)
at System.IO.Directory.GetFiles(String path)
at TestTrust.Program.Main(String[] args)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission
The Zone of the assembly that failed was:
Intranet

Here is the sample application:
-------------------------------------------
using System;
using System.IO;
using System.Security.AccessControl;
using System.Security.Permissions;

class Program
{
static void Main()
{
try
{
Console.WriteLine(".");
new FileIOPermission(FileIOPermissionAccess.Read, @"c:
\").Demand();
Console.WriteLine(".");
new FileIOPermission(FileIOPermissionAccess.PathDiscov ery,
AccessControlActions.View, @"c:\").Demand();
Console.WriteLine(".");
new FileIOPermission(PermissionState.Unrestricted).Dem and();
Console.WriteLine(".");
Directory.GetFiles(@"c:\");
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadLine();
}
}
Aug 18 '08 #1
1 2748
Short Version:

When running managed code from a network drive, with default security
settings, calling Demand() on the following permission objects runs
with no exceptions:

new FileIOPermission(FileIOPermissionAccess.Read, @"c:\")
new FileIOPermission(FileIOPermissionAccess.PathDiscov ery,
AccessControlActions.View, @"c:\")
new FileIOPermission(PermissionState.Unrestricted)

And then this line of code throws a SecurityException "Request for the
permission of type [...] FileIOPermission [...] failed. ":

Directory.GetFiles(@"c:\");

So, what does FileIOPermission.Demand actually do, since it doesn't
seem to check if the specified FileIOPermission exists?
Aug 19 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mircea Pleteriu | last post by:
Hi all, I have this code sample FileIOPermission fp = new FileIOPermission(PermissionState.Unrestricted); fp.Deny(); StreamWriter sw = new StreamWriter(@"c:\test.txt");
2
by: AMerrell | last post by:
Hi, I wrote a vb app to display a message that is read from a text file. This app will be called by our Novell Logon script. I wrote and tested the app on my local windows xp system and...
0
by: John Delange | last post by:
Hello, I wrote a .NET Windows.Forms User Control that needs to be runned through Internet Explorer, like in this article: http://www.15seconds.com/issue/030610.htm. This control needs to 1.) Run...
0
by: KM | last post by:
I have seen numerous explanations about .NET security and the System.Security.Permissions.FileIOPermission but any suggestions I have tried have failed. I have a an exe which is launched from a...
1
by: Usman Ghani | last post by:
Hi, I am trying to develop an activex control with the .Net by exposing an interface to the com as described in the following article....
6
by: schaf | last post by:
Hi NG ! I have the following piece of code below. the first try/catch part would return true although I do not have permission to access this computer. The second try/catch part would return...
1
by: Marquis | last post by:
I have put the C# Form onito the Internet as an ActiveX Control. However, I cannot do the FileOpen Dialog as I don't have permission, how to solve this problem? Below is the error code:...
3
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type...
2
by: Dave | last post by:
Yesterday I posted: **************************** I'm trying to download a file from the Web Server to the user's desktop using myWebClient.DownloadFile as described by Microsoft at...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.