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 接口。

适用于