Share via


FileSystemAccessRule Sınıf

Tanım

Bir dosya veya dizin için erişim kuralı tanımlayan erişim denetimi girişinin (ACE) soyutlamasını temsil eder. Bu sınıf devralınamaz.

public ref class FileSystemAccessRule sealed : System::Security::AccessControl::AccessRule
public sealed class FileSystemAccessRule : System.Security.AccessControl.AccessRule
[System.Security.SecurityCritical]
public sealed class FileSystemAccessRule : System.Security.AccessControl.AccessRule
type FileSystemAccessRule = class
    inherit AccessRule
[<System.Security.SecurityCritical>]
type FileSystemAccessRule = class
    inherit AccessRule
Public NotInheritable Class FileSystemAccessRule
Inherits AccessRule
Devralma
FileSystemAccessRule
Öznitelikler

Örnekler

Aşağıdaki kod örneği, bir dosyaya erişim denetimi girdisi (ACE) eklemek ve kaldırmak için sınıfını kullanır FileSecurity . Bu örneği çalıştırmak için geçerli bir kullanıcı veya grup hesabı sağlamanız gerekir.

using namespace System;
using namespace System::IO;
using namespace System::Security::AccessControl;

// Adds an ACL entry on the specified file for the specified account.

void AddFileSecurity(String^ fileName, String^ account, 
                        FileSystemRights rights, AccessControlType controlType)
{
    // Get a FileSecurity object that represents the 
    // current security settings.
    FileSecurity^ fSecurity = File::GetAccessControl(fileName);

    // Add the FileSystemAccessRule to the security settings. 
    fSecurity->AddAccessRule(gcnew FileSystemAccessRule
                                   (account,rights, controlType));

    // Set the new access settings.
    File::SetAccessControl(fileName, fSecurity);
}

// Removes an ACL entry on the specified file for the specified account.

void RemoveFileSecurity(String^ fileName, String^ account, 
                        FileSystemRights rights, AccessControlType controlType)
{

    // Get a FileSecurity object that represents the 
    // current security settings.
    FileSecurity^ fSecurity = File::GetAccessControl(fileName);

    // Remove the FileSystemAccessRule from the security settings. 
    fSecurity->RemoveAccessRule(gcnew FileSystemAccessRule
                                      (account,rights, controlType));

    // Set the new access settings.
    File::SetAccessControl(fileName, fSecurity);
}

int main()
{
    try
    {
        String^ fileName = "test.xml";

        Console::WriteLine("Adding access control entry for " + fileName);

        // Add the access control entry to the file.
        AddFileSecurity(fileName, "MYDOMAIN\\MyAccount", 
            FileSystemRights::ReadData, AccessControlType::Allow);

        Console::WriteLine("Removing access control entry from " + fileName);

        // Remove the access control entry from the file.
        RemoveFileSecurity(fileName, "MYDOMAIN\\MyAccount", 
            FileSystemRights::ReadData, AccessControlType::Allow);

        Console::WriteLine("Done.");
    }
    catch (Exception^ ex)
    {
        Console::WriteLine(ex->Message);
    }
}
using System;
using System.IO;
using System.Security.AccessControl;

namespace FileSystemExample
{
    class FileExample
    {
        public static void Main()
        {
            try
            {
                string fileName = "test.xml";

                Console.WriteLine("Adding access control entry for "
                    + fileName);

                // Add the access control entry to the file.
                AddFileSecurity(fileName, @"DomainName\AccountName",
                    FileSystemRights.ReadData, AccessControlType.Allow);

                Console.WriteLine("Removing access control entry from "
                    + fileName);

                // Remove the access control entry from the file.
                RemoveFileSecurity(fileName, @"DomainName\AccountName",
                    FileSystemRights.ReadData, AccessControlType.Allow);

                Console.WriteLine("Done.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }

        // Adds an ACL entry on the specified file for the specified account.
        public static void AddFileSecurity(string fileName, string account,
            FileSystemRights rights, AccessControlType controlType)
        {

            // Get a FileSecurity object that represents the
            // current security settings.
            FileSecurity fSecurity = File.GetAccessControl(fileName);

            // Add the FileSystemAccessRule to the security settings.
            fSecurity.AddAccessRule(new FileSystemAccessRule(account,
                rights, controlType));

            // Set the new access settings.
            File.SetAccessControl(fileName, fSecurity);
        }

        // Removes an ACL entry on the specified file for the specified account.
        public static void RemoveFileSecurity(string fileName, string account,
            FileSystemRights rights, AccessControlType controlType)
        {

            // Get a FileSecurity object that represents the
            // current security settings.
            FileSecurity fSecurity = File.GetAccessControl(fileName);

            // Remove the FileSystemAccessRule from the security settings.
            fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,
                rights, controlType));

            // Set the new access settings.
            File.SetAccessControl(fileName, fSecurity);
        }
    }
}
Imports System.IO
Imports System.Security.AccessControl



Module FileExample

    Sub Main()
        Try
            Dim fileName As String = "test.xml"

            Console.WriteLine("Adding access control entry for " & fileName)

            ' Add the access control entry to the file.
            AddFileSecurity(fileName, "DomainName\AccountName", _
                FileSystemRights.ReadData, AccessControlType.Allow)

            Console.WriteLine("Removing access control entry from " & fileName)

            ' Remove the access control entry from the file.
            RemoveFileSecurity(fileName, "DomainName\AccountName", _
                FileSystemRights.ReadData, AccessControlType.Allow)

            Console.WriteLine("Done.")
        Catch e As Exception
            Console.WriteLine(e)
        End Try

    End Sub


    ' Adds an ACL entry on the specified file for the specified account.
    Sub AddFileSecurity(ByVal fileName As String, ByVal account As String, _
        ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)
  
        ' Get a FileSecurity object that represents the 
        ' current security settings.
        Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)

        ' Add the FileSystemAccessRule to the security settings. 
        Dim accessRule As FileSystemAccessRule = _
            New FileSystemAccessRule(account, rights, controlType)

        fSecurity.AddAccessRule(accessRule)

        ' Set the new access settings.
        File.SetAccessControl(fileName, fSecurity)

    End Sub


    ' Removes an ACL entry on the specified file for the specified account.
    Sub RemoveFileSecurity(ByVal fileName As String, ByVal account As String, _
        ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)

        ' Get a FileSecurity object that represents the 
        ' current security settings.
        Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)

        ' Remove the FileSystemAccessRule from the security settings. 
        fSecurity.RemoveAccessRule(New FileSystemAccessRule(account, _
            rights, controlType))

        ' Set the new access settings.
        File.SetAccessControl(fileName, fSecurity)

    End Sub
End Module

Açıklamalar

sınıfı FileSystemAccessRule , bir kullanıcı hesabını, sağlanması gereken erişim türünü (okuma, yazma vb.) ve bu haka izin verilip verilmeyeceğini belirten temel erişim denetimi girişinin (ACE) soyutlamasını temsil eder. Bu sınıf, erişim kurallarının alt nesnelere nasıl yayılacağını da belirtebilir.

Yeni bir erişim kuralı oluşturmak için sınıfını FileSystemAccessRule kullanın. veya DirectorySecurity sınıfını kullanarak FileSecurity kuralı kalıcı hale ekleyebilirsiniz.

Oluşturucular

FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType)

Kullanıcı hesabına başvuru, erişim kuralıyla ilişkili işlem türünü belirten bir değer ve işleme izin verilip verilmeyeceğini belirten bir değer kullanarak sınıfın yeni bir örneğini FileSystemAccessRule başlatır.

FileSystemAccessRule(IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)

Kullanıcı hesabına başvuru kullanarak sınıfın FileSystemAccessRule yeni bir örneğini başlatır, erişim kuralıyla ilişkili işlem türünü belirten bir değer, hakların nasıl devralındığını belirleyen bir değer, hakların nasıl yayıldığını belirleyen bir değer ve işleme izin verilip verilmeyeceğini belirten bir değer.

FileSystemAccessRule(String, FileSystemRights, AccessControlType)

Kullanıcı hesabının adını, erişim kuralıyla ilişkili işlem türünü belirten bir değeri ve işleme izin verilip verilmeyeceğini açıklayan bir değeri kullanarak sınıfın yeni bir örneğini FileSystemAccessRule başlatır.

FileSystemAccessRule(String, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)

Kullanıcı hesabının adını, erişim kuralıyla ilişkili işlem türünü belirten bir değer, hakların nasıl devralındığını belirleyen bir değer, hakların nasıl yayıldığını belirleyen bir değer ve işleme izin verilip verilmeyeceğini belirten bir değer kullanarak sınıfın yeni bir örneğini FileSystemAccessRule başlatır.

Özellikler

AccessControlType

AccessControlType Bu AccessRule nesneyle ilişkili değeri alır.

(Devralındığı yer: AccessRule)
AccessMask

Bu kural için erişim maskesini alır.

(Devralındığı yer: AuthorizationRule)
FileSystemRights

FileSystemRights Geçerli FileSystemAccessRule nesneyle ilişkili bayrakları alır.

IdentityReference

Bu kuralın IdentityReference uygulandığı değeri alır.

(Devralındığı yer: AuthorizationRule)
InheritanceFlags

Bu kuralın alt nesneler tarafından nasıl devralındığını belirleyen bayrakların değerini alır.

(Devralındığı yer: AuthorizationRule)
IsInherited

Bu kuralın açıkça ayarlandığını veya bir üst kapsayıcı nesnesinden devralındığını belirten bir değer alır.

(Devralındığı yer: AuthorizationRule)
PropagationFlags

Bu kuralın devralma işleminin alt nesnelere nasıl yayıldığına karar veren yayma bayraklarının değerini alır. Bu özellik yalnızca sabit listesi değeri InheritanceFlags olmadığında Noneönemlidir.

(Devralındığı yer: AuthorizationRule)

Yöntemler

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır