LinkDemand does not work

  • Thread starter Thread starter fred
  • Start date Start date
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
 
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
 
Back
Top