SocketPermission.IsSubsetOf(IPermission) 方法

定義

判斷目前使用權限是否為指定之使用權限的子集。

public:
 override bool IsSubsetOf(System::Security::IPermission ^ target);
public override bool IsSubsetOf (System.Security.IPermission target);
override this.IsSubsetOf : System.Security.IPermission -> bool
Public Overrides Function IsSubsetOf (target As IPermission) As Boolean

參數

target
IPermission

要測試其子集關聯性的 SocketPermission

傳回

targetnull 的情況下,如果目前執行個體沒有定義使用權限,則這個方法會傳回 true,否則傳回 false。 在 target 不是 null 的情況下,如果目前執行個體定義了 target 使用權限的子集,則這個方法會傳回 true,否則傳回 false

例外狀況

DnsPermission 沒有授與方法呼叫端。

範例

下列範例會 IsSubsetOf 使用 方法來判斷其中一個是否為另一個 SocketPermission 子集。

// Creates a SocketPermission restricting access to and from all URIs.
SocketPermission^ mySocketPermission1 = gcnew SocketPermission( PermissionState::None );

// The socket to which this permission will apply will allow connections from www.contoso.com.
mySocketPermission1->AddPermission( NetworkAccess::Accept, TransportType::Tcp,  "www.contoso.com", 11000 );

// Creates a SocketPermission which will allow the target Socket to connect with www.southridgevideo.com.
SocketPermission^ mySocketPermission2 = gcnew SocketPermission( NetworkAccess::Connect,TransportType::Tcp, "www.southridgevideo.com",11002 );

// Creates a SocketPermission from the union of two SocketPermissions.
SocketPermission^ mySocketPermissionUnion =
   (SocketPermission^)( mySocketPermission1->Union( mySocketPermission2 ) );

// Checks to see if the union was successfully created by using the IsSubsetOf method.
if ( mySocketPermission1->IsSubsetOf( mySocketPermissionUnion ) &&
   mySocketPermission2->IsSubsetOf( mySocketPermissionUnion ) )
{
   Console::WriteLine(  "This union contains permissions from both mySocketPermission1 and mySocketPermission2" );
   
   // Prints the allowable accept URIs to the console.
   Console::WriteLine(  "This union accepts connections on :" );

   IEnumerator^ myEnumerator = mySocketPermissionUnion->AcceptList;
   while ( myEnumerator->MoveNext() )
   {
      Console::WriteLine( safe_cast<EndpointPermission^>( myEnumerator->Current )->ToString() );
   }
   
   // Prints the allowable connect URIs to the console.
   Console::WriteLine(  "This union permits connections to :" );

   myEnumerator = mySocketPermissionUnion->ConnectList;
   while ( myEnumerator->MoveNext() )
   {
      Console::WriteLine( safe_cast<EndpointPermission^>( myEnumerator->Current )->ToString() );
   }
}

// Creates a SocketPermission restricting access to and from all URIs.
SocketPermission mySocketPermission1 = new SocketPermission(PermissionState.None);

// The socket to which this permission will apply will allow connections from www.contoso.com.
mySocketPermission1.AddPermission(NetworkAccess.Accept, TransportType.Tcp, "www.contoso.com", 11000);

// Creates a SocketPermission which will allow the target Socket to connect with www.southridgevideo.com.
SocketPermission mySocketPermission2 =
                           new SocketPermission(NetworkAccess.Connect, TransportType.Tcp, "www.southridgevideo.com", 11002);

// Creates a SocketPermission from the union of two SocketPermissions.
SocketPermission mySocketPermissionUnion =
                           (SocketPermission)mySocketPermission1.Union(mySocketPermission2);

// Checks to see if the union was successfully created by using the IsSubsetOf method.
if (mySocketPermission1.IsSubsetOf(mySocketPermissionUnion) &&
      mySocketPermission2.IsSubsetOf(mySocketPermissionUnion)){
     Console.WriteLine("This union contains permissions from both mySocketPermission1 and mySocketPermission2");

     // Prints the allowable accept URIs to the console.
     Console.WriteLine("This union accepts connections on :");

     IEnumerator myEnumerator = mySocketPermissionUnion.AcceptList;
  while (myEnumerator.MoveNext()) {
          Console.WriteLine(((EndpointPermission)myEnumerator.Current).ToString());
       }

        // Prints the allowable connect URIs to the console.
     Console.WriteLine("This union permits connections to :");

     myEnumerator = mySocketPermissionUnion.ConnectList;
  while (myEnumerator.MoveNext()) {
          Console.WriteLine(((EndpointPermission)myEnumerator.Current).ToString());
       }
      }
' Creates a SocketPermission restricting access to and from all URIs.
Dim mySocketPermission1 As New SocketPermission(PermissionState.None)

' The socket to which this permission will apply will allow connections from www.contoso.com.
mySocketPermission1.AddPermission(NetworkAccess.Accept, TransportType.Tcp, "www.contoso.com", 11000)

' Creates a SocketPermission which will allow the target Socket to connect with www.southridgevideo.com.
Dim mySocketPermission2 As New SocketPermission(NetworkAccess.Connect, TransportType.Tcp, "www.southridgevideo.com", 11002)

' Creates a SocketPermission from the union of two SocketPermissions.
Dim mySocketPermissionUnion As SocketPermission = CType(mySocketPermission1.Union(mySocketPermission2), SocketPermission)

' Checks to see if the union was successfully created by using the IsSubsetOf method.
If mySocketPermission1.IsSubsetOf(mySocketPermissionUnion) And mySocketPermission2.IsSubsetOf(mySocketPermissionUnion) Then
   Console.WriteLine("This union contains permissions from both mySocketPermission1 and mySocketPermission2")
   
   ' Prints the allowable accept URIs to the console.
   Console.WriteLine("This union accepts connections on :")
   
   Dim myEnumerator As IEnumerator = mySocketPermissionUnion.AcceptList
   While myEnumerator.MoveNext()
      Console.WriteLine(CType(myEnumerator.Current, EndpointPermission).ToString())
   End While
   
   Console.WriteLine("This union establishes connections on : ")
   
   ' Prints the allowable connect URIs to the console.
   Console.WriteLine("This union permits connections to :")
   
   myEnumerator = mySocketPermissionUnion.ConnectList
   While myEnumerator.MoveNext()
      Console.WriteLine(CType(myEnumerator.Current, EndpointPermission).ToString())
   End While
End If

備註

如果目前許可權指定一組完全由指定許可權所包含的作業,則目前的許可權是指定許可權的子集。

例如,代表 192.168.1.1:80 存取權的許可權子集,代表 192.168.1.1:Any 的存取權。 如果這個方法傳 true 回 ,則目前的許可權代表對受保護資源的存取權,而不是指定的許可權。

適用於