O'Reilly logo

Programming .NET Security by Allen Jones, Adam Freeman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inspecting Declarative Security Statements

The Permissions View tool (Permview.exe) allows you to view the declarative security statements used in an assembly. This is particularly useful when configuring security policy, as it allows you to view the permission requests contained in the assembly. Permview.exe is located in the \bin subdirectory of the .NET Framework SDK installation directory. Note that the \bin directory is not added to the Path environment variable by the SDK-installation process.

Tip

Permview.exe only shows declarative security statements and cannot extract the imperative security demands. It overrides from the body of an assembly.

To demonstrate Permview.exe, use the MessageUtil class shown here, which allows any caller to display a message box containing the value of the Message environment variable. MessageUtil uses three RequestMinumum permission requests to ensure that it has permission to read the Message environment variable, called Assert, and display safe top-level windows (such as message boxes). The DisplayMessage method uses declarative syntax to Assert UIPermission and EnvironmentPermission. This allows any client code to use DisplayMessage regardless of the caller's permissions:

# C# using System; using System.Windows.Forms; using System.Security.Permissions; // Request read access to the Message environment variable. [assembly:EnvironmentPermission(SecurityAction.RequestMinimum, Read = "Message")] // Request permission to Assert. [assembly:SecurityPermission(SecurityAction.RequestMinimum, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required