当前位置: 首页>>代码示例>>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;未经允许,请勿转载。