Determining How Resource Protection Is Implemented

The most straightforward way to protect a resource is by explicitly using permissions. Permissions explicitly protecting resources in the secure class library code will look something like the following if used imperatively:

new FileIOPermission(FileIOPermissionAccess.AllAccess, @"C:\ mydir\ myapp.xml").Demand();

or something like the following if used declaratively:

[FileIOPermission(SecurityAction.Demand, All=@"C:\ mydir\ myapp.xml")]

In all cases of explicit protection, there will be some kind of Demand, LinkDemand, or InheritanceDemand in the code. Demands may occur either imperatively or declaratively. LinkDemands and InheritanceDemands will only be found in declarative form.

In my experience, ...

Get .NET Framework Security now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.