Hi friends,
I wrote the following code to test the CAS:
[SecurityPermission(SecurityAction.Demand,Flags=SecurityPermissionFlag.Execution)]
static void Main(string[] args)
{
Console.WriteLine("hello, world!");
}
In the .NET 2.0 Configuration, I use the strong name of the above assembly to create a code group and give the group Nothing permission set. So the assembly failed to start as expected.
But I noticed that if I remove the following attribute:
[SecurityPermission(SecurityAction.Demand,Flags=SecurityPermissionFlag.Execution)]
The program still failed to start. So what's the point of this so-called declarative security with attribute?
I read several tutorials on CAS, they use Imperative/Declarative Security to use the CAS. But from the above sample, it doesn't seem necessary.
If I deliberately write code without Imperative/Declarative Security and don't provide any evidence for my assembly, would CAS be blind to enforce any security policy?
Or do I misunderstand how CAS is expected to be used?
Thanks.