Re: SecurityPermission problem
- From: "Nicole Calinoiu" <calinoiu REMOVETHIS AT gmail DOT com>
- Date: Thu, 30 Mar 2006 10:03:42 -0500
The Demand method skips the call stack frame for the method from which it is called. In order to have your assembly included in the stack walk initiated by Demand, you'll need to move it into a separate method since the Main method has no within-assembly callers. e.g.:
static void Main(string[] args)
{
DemandFileIOPermission();
FileStream fw = new FileStream("c:\\hello.txt", FileMode.Create);
}
private static void DemandFileIOPermission()
{
FileIOPermission fip = new FileIOPermission(FileIOPermissionAccess.AllAccess, "c:\\hello.txt");
fip.Demand();
}
"Itay Sandbank" <ItaySandbank@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:B50075F7-3042-45F6-901E-3B295B5D191A@xxxxxxxxxxxxxxxx
Hi.
I'm trying to understand how to use CAS, and found something strange. I'm
trying to deny my program of a few permissions to see what happens. I created
a small program that creates the file c:\hello.txt and exits:
[assembly: FileIOPermission(SecurityAction.RequestRefuse,
ViewAndModify="c:\\")]
namespace CodeAccessSecurity
{
class Program
{
static void Main(string[] args)
{
FileIOPermission fip = new
FileIOPermission(FileIOPermissionAccess.AllAccess, "c:\\hello.txt");
fip.Demand();
FileStream fw = new FileStream("c:\\hello.txt", FileMode.Create);
}
}
}
When I run it, I see a SecurityException thrown, as can be expected.
However, it is thrown when I create the FileStream and not when I Demand the
FileIOPermission.
When running from the local intranet zone (I changed the debugger's
security settings), the exception is thrown on the Demand - as I expected in
the first place.
What's going on here?
Thanks,
Itay.
.
- Follow-Ups:
- Re: SecurityPermission problem
- From: Itay Sandbank
- Re: SecurityPermission problem
- Prev by Date: Re: Best practice SecureString and pswd collection
- Next by Date: Re: Best practice SecureString and pswd collection
- Previous by thread: Best practice SecureString and pswd collection
- Next by thread: Re: SecurityPermission problem
- Index(es):