SecurityAttribute.Unrestricted issue

2019-02-15 14:12发布

问题:

I am confused about this property, as mentioned here, http://msdn.microsoft.com/en-us/library/system.security.permissions.securityattribute.unrestricted.aspx we could give it full or non-full.

My confusion is for permission in a straightforward understanding, there should be only two status -- granted and not-granted, what does th full and non-full mean?

回答1:

I have previously used the Unrestricted attribute in the classic way:

The following code is a request stating that an assembly must have unrestricted access to the file system in order to function.

using System.Security.Permissions;
// Indicates that FileIOPermission is required to run this assembly.
[assembly:FileIOPermission(SecurityAction.RequestMinimum, Unrestricted=true)]
public class FileManager
{
// Insert code to add and delete files.
}

in this context Unrestricted=false would mean file access is not nessessarily required, for the method to execute.

as opposed to the 'oppisite' which would require that in order for the method to execute, file access must not be granted.

In most cases where the SecurityAction (Unrestricted=true||false) may be created dynamicaly, the first case usually makes more sense.