LinkDemand does not work

F

fred

hi,

does anybody know why this code does not raise a
SecurityException?

using System;
using System.Security.Permissions;
using System.Security;

namespace MyNameSpace
{
class MainClass
{
static void Main(string[] args)
{
ClassA ca = new ClassA();
Console.WriteLine(ca.StackWalker
());
Console.Read();
}
}

public class ClassA
{
[FileIOPermission
(SecurityAction.Deny,Write = @"c:\foo.txt")]
public string StackWalker()
{
ClassB cb = new ClassB();
return "From ClassA: " +
cb.StackWalker();
}
}

public class ClassB
{
[FileIOPermission
(SecurityAction.LinkDemand,Write = @"c:\foo.txt")]
public string StackWalker()
{
return "I'm in ClassB";
}
}
}

thank you
 
N

Nicole Calinoiu

Fred,

Deny is a stack walk modifier, it doesn't actually deny a permission to any
assembly. Link demands do not cause stack walks, so stack walk modifiers
won't affect any link demand. If you used a full demand, you will see the
exception you expect.

HTH,
Nicole
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top