當前位置: 首頁>>代碼示例>>C#>>正文


C# FileSecurity.SetAccessRuleProtection方法代碼示例

本文整理匯總了C#中System.Security.AccessControl.FileSecurity.SetAccessRuleProtection方法的典型用法代碼示例。如果您正苦於以下問題:C# FileSecurity.SetAccessRuleProtection方法的具體用法?C# FileSecurity.SetAccessRuleProtection怎麽用?C# FileSecurity.SetAccessRuleProtection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Security.AccessControl.FileSecurity的用法示例。


在下文中一共展示了FileSecurity.SetAccessRuleProtection方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetSecuritySettings

 static private FileSecurity GetSecuritySettings() {
    FileSecurity security = new FileSecurity();
    security.SetAccessRuleProtection(true, false);
    security.AddAccessRule(
       (FileSystemAccessRule) security.AccessRuleFactory(
                                 new NTAccount(
                                    WindowsIdentity.GetCurrent().Name),
                                 // Full control
                                 -1,
                                 false,
                                 InheritanceFlags.None,
                                 PropagationFlags.None,
                                 AccessControlType.Allow));
    return security;
 }
開發者ID:Nikolay-Krasan,項目名稱:DegreeWork,代碼行數:15,代碼來源:CredentialStore.cs

示例2: GetSecureFileStream

    public static FileStream GetSecureFileStream(string path, int bufferSize, FileOptions options)
    {
      if (path == null)
        throw new ArgumentNullException("path");

      if (bufferSize <= 0)
        throw new ArgumentOutOfRangeException("bufferSize");

      if ((options &
           ~(FileOptions.Asynchronous | FileOptions.DeleteOnClose | FileOptions.Encrypted | FileOptions.RandomAccess |
             FileOptions.SequentialScan | FileOptions.WriteThrough)) != FileOptions.None)
        throw new ArgumentOutOfRangeException("options");

      new FileIOPermission(FileIOPermissionAccess.Write, path).Demand();

      SecurityIdentifier user = WindowsIdentity.GetCurrent().User;
      FileSecurity fileSecurity = new FileSecurity();
      fileSecurity.AddAccessRule(new FileSystemAccessRule(user, FileSystemRights.FullControl, AccessControlType.Allow));
      fileSecurity.SetAccessRuleProtection(true, false);

      fileSecurity.SetOwner(user);

      // Attempt to create a unique file three times before giving up.
      // It is highly improbable that there will ever be a name clash,
      // therefore we do not check to see if the file first exists.
      for (int attempt = 0; attempt < 3; attempt++)
      {
        try
        {
          return new FileStream(Path.Combine(path, Path.GetRandomFileName()), FileMode.CreateNew,
                                FileSystemRights.FullControl, FileShare.None, bufferSize, options, fileSecurity);
        }
        catch (IOException)
        {
          if (attempt == 2)
            throw;
        }
      }
      // This code can never be reached.
      // The compiler thinks otherwise.
      throw new IOException();
    }
開發者ID:arangas,項目名稱:MediaPortal-1,代碼行數:42,代碼來源:PathUtility.cs

示例3: RestrictAdminAccess

		private void RestrictAdminAccess(string path)
		{
			FileSecurity fileSecurity = new FileSecurity();
			fileSecurity.SetAccessRuleProtection(true, false);
			SecurityIdentifier securityIdentifier = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
			FileSystemRights fileSystemRight = FileSystemRights.FullControl;
			AccessControlType accessControlType = AccessControlType.Allow;
			FileSystemAccessRule fileSystemAccessRule = new FileSystemAccessRule(securityIdentifier, fileSystemRight, accessControlType);
			fileSecurity.AddAccessRule(fileSystemAccessRule);
			File.SetAccessControl(path, fileSecurity);
		}
開發者ID:nickchal,項目名稱:pash,代碼行數:11,代碼來源:PswaAuthorizationRuleManager.cs


注:本文中的System.Security.AccessControl.FileSecurity.SetAccessRuleProtection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。