With the exceptions described in the previous bulleted list for deprecated security actions, applying permissions in the new security model is similar to the previous versions of the .NET Framework. This means that you can leverage permissions from the System.Security.Permissions
namespace, such as FileIOPermission
, UIPermission
, IsolatedStoragePermission
, and EnvironmentPermission
. The following code demonstrates how you use the declarative syntax for implementing a class that requires the caller code having the FileIOPermission
to execute. Such a class simply implements a method that returns an XDocument
from a text file:
You can also use the imperative syntax, which looks like this:
You create an instance of the required permission and then invoke Demand
for checking if the application has that level of permissions. If not, a System.Security.Security Exception
is thrown.
3.145.177.115