In C# 4.0+, is there a good way to restrict the allowable callers of a method, based on a method attribute?
I naively thought this was what CAS was all about -- and now the changes in .NET 4.0 appear to say the new CAS is only applied at the assembly level, and only on sandboxed apps ... which isn't what I'm after.
I'm imagining something like this:
[MyDangerousPermission]
public void DoSomethingDangerous()
{
. . .
}
and in another class or assembly:
[MyDangerousDemand]
public void AllowedCaller()
{
DoSomethingDangerous();
}
and that without [MyDangerousDemand]
somewhere in the call stack, any calls to DoSomethingDangerous()
would fail (throw a SecurityException
, for example).
Not possible?
(my main application is in a web app, in case it matters).