
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Obtaining Security/Audit Information
|
985
One serious consideration with this approach is that the use of RequestRefuse marks
your assembly as partially trusted. This in turn prevents it from calling any strong-
named assembly that hasn’t been marked with the
AllowPartiallyTrustedCallers
attribute.
See Also
See Chapter 8 of Microsoft Patterns & Practices Group: http://msdn.microsoft.com/
library/default.asp?url=/library/en-us/dnnetsec/html/THCMCh08.asp; see the “Secu-
rityAction Enumeration” and “Global Attributes” topics in the MSDN documentation.
17.13 Obtaining Security/Audit Information
Problem
You need to obtain the security rights and/or audit information for a file or registry
key.
Solution
When obtaining security/audit information for a file, use the static GetAccessControl
method of the File class to obtain a System.Security.AccessControl.FileSecurity
object. Use the FileSecurity object to access the security and audit information for
the file. These steps are demonstrated in Example 17-15.
Example 17-15. Obtaining security audit information
public static void ViewFileRights( )
{
// Get security information from a file.
string file = @"c:\FOO.TXT";
FileSecurity fileSec = File.GetAccessControl(file);
DisplayFileSecurityInfo(fileSec);
}
public static void DisplayFileSecurityInfo(FileSecurity ...