How to: Request Minimum Permissions by Using the RequestMinimum Flag
flag allows you to request a minimum set of permissions your code requires to execute. By contrast, the flag allows you to refuse permissions by explicitly specifying which ones your code should not be granted.
In contrast to using the RequestMinimum flag, your application will execute if it does not receive all the permissions that you request using theflag, and a will be thrown when your application attempts to access a protected resource. If you use this type of request, you must enable your code to catch any exceptions that will be thrown if your code is not granted the optional permission.
The following example requestsusing the RequestMinimum flag. The example will not execute if it has not been granted the requested permission. This example assumes that a hypothetical class Log exists in LogNameSpace. The Log class contains the MakeLog method that creates a new log file on the local computer. This application creates a new instance of the Log class and executes the MakeLog method in the try block. Using the catch keyword, it intercepts any SecurityException thrown and displays a message.
The previous code creates the log file and displays the following message to the console if it has sufficient permissions:
The Log has been created.
If the code is run from a share and the local security settings do not allow such code to have FileIOPermission, the code is not granted sufficient permission and displays the following message:
This application does not have permission to write to the disk.