共用方式為


WebPermission.IsSubsetOf(IPermission) 方法

定義

判斷目前 WebPermission 是否為指定物件的子集。

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

要與目前 WebPermission 比較的 WebPermission

傳回

如果目前的執行個體是 target 參數的子集,則為 true,否則為 false。 如果目標為 null,則方法會傳回 true,表示目前為空的不受限制的使用權限,否則傳回 false

例外狀況

目標參數不是 WebPermission 的執行個體。

目前執行個體含有 Regex 編碼權限,且在目標執行個體中找不到完全相同的權限。

範例

下列範例會使用 IsSubsetOf 來判斷某個 實例 WebPermission 中找到的訪問許可權是否在另一個 實例 WebPermission中找到。

// Create the target permission.
WebPermission^ targetPermission = gcnew WebPermission;
targetPermission->AddPermission( NetworkAccess::Connect, gcnew Regex( "www\\.contoso\\.com/Public/.*" ) );

// Create the permission for a URI matching target.
WebPermission^ connectPermission = gcnew WebPermission;
connectPermission->AddPermission( NetworkAccess::Connect, "www.contoso.com/Public/default.htm" );

//The following statement prints true.
Console::WriteLine( "Is the second URI a subset of the first one?: {0}", connectPermission->IsSubsetOf( targetPermission ) );

// Create the target permission.
WebPermission targetPermission = new WebPermission();
targetPermission.AddPermission(NetworkAccess.Connect, new Regex("www\\.contoso\\.com/Public/.*"));

// Create the permission for a URI matching target.
WebPermission connectPermission = new WebPermission();
connectPermission.AddPermission(NetworkAccess.Connect, "www.contoso.com/Public/default.htm");

//The following statement prints true.
Console.WriteLine("Is the second URI a subset of the first one?: " + connectPermission.IsSubsetOf(targetPermission));
   ' Create the target permission.
   Dim targetPermission As New WebPermission()
   targetPermission.AddPermission(NetworkAccess.Connect, New Regex("www\.contoso\.com/Public/.*"))
   
   ' Create the permission for a URI matching target.
   Dim connectPermission As New WebPermission()
   connectPermission.AddPermission(NetworkAccess.Connect, "www.contoso.com/Public/default.htm")
   
   'The following statement prints true.
   Console.WriteLine(("Is the second URI a subset of the first one?: " & connectPermission.IsSubsetOf(targetPermission)))
End Sub

備註

如果目前 WebPermission 指定參數完全包含 target 的一組相關聯資源,則目前的 WebPermission 是的 target子集。 這個方法會 IsSubsetOf 覆寫 並實作以支援 IPermission 介面。

適用於