Share via


PolicyLevel.Resolve(Evidence) 方法

定义

根据策略级别的证据移除策略,并返回产生的 PolicyStatement

public:
 System::Security::Policy::PolicyStatement ^ Resolve(System::Security::Policy::Evidence ^ evidence);
public System.Security.Policy.PolicyStatement Resolve (System.Security.Policy.Evidence evidence);
member this.Resolve : System.Security.Policy.Evidence -> System.Security.Policy.PolicyStatement
Public Function Resolve (evidence As Evidence) As PolicyStatement

参数

evidence
Evidence

用于解析 EvidencePolicyLevel

返回

生成的 PolicyStatement

例外

策略级别包含多个标记为独占的匹配代码组。

evidence 参数为 null

示例

以下代码演示如何使用 Resolve 方法。 此代码示例是为 PolicyLevel 类提供的一个更大示例的一部分。

// Demonstrate the use of ResolvePolicy for the supplied evidence and a specified policy level.
void CheckEvidence( PolicyLevel^ pLevel, Evidence^ evidence )
{
   // Display the code groups to which the evidence belongs.
   Console::WriteLine( "\tResolvePolicy for the given evidence: " );
   IEnumerator^ codeGroup = evidence->GetEnumerator();
   while ( codeGroup->MoveNext() )
   {
      Console::WriteLine( "\t\t{0}", (dynamic_cast<CodeGroup^>(codeGroup->Current))->Name );
   }

   Console::WriteLine( "The current evidence belongs to the following root CodeGroup:" );

   // pLevel is the current PolicyLevel, evidence is the Evidence to be resolved.
   CodeGroup^ cg1 = pLevel->ResolveMatchingCodeGroups( evidence );
   Console::WriteLine( "{0} Level", pLevel->Label );
   Console::WriteLine( "\tRoot CodeGroup = {0}", cg1->Name );

   // Show how Resolve is used to determine the set of permissions that 
   // the security system grants to code, based on the evidence.
   // Show the granted permissions. 
   Console::WriteLine( "\nCurrent permissions granted:" );
   PolicyStatement^ pState = pLevel->Resolve( evidence );
   Console::WriteLine( pState->ToXml() );
   return;
}
// Demonstrate the use of ResolvePolicy for the supplied evidence and a specified policy level.
private static void CheckEvidence(PolicyLevel pLevel, Evidence evidence)
{
    // Display the code groups to which the evidence belongs.
    Console.WriteLine("\tResolvePolicy for the given evidence: ");
    IEnumerator codeGroup = evidence.GetEnumerator();
    while (codeGroup.MoveNext())
    {
        Console.WriteLine("\t\t" + ((CodeGroup)codeGroup.Current).Name);
    }
    Console.WriteLine("The current evidence belongs to the following root CodeGroup:");
    // pLevel is the current PolicyLevel, evidence is the Evidence to be resolved.
    CodeGroup cg1 = pLevel.ResolveMatchingCodeGroups(evidence);
    Console.WriteLine(pLevel.Label + " Level");
    Console.WriteLine("\tRoot CodeGroup = " + cg1.Name);

    // Show how Resolve is used to determine the set of permissions that 
    // the security system grants to code, based on the evidence.

    // Show the granted permissions. 
    Console.WriteLine("\nCurrent permissions granted:");
    PolicyStatement pState = pLevel.Resolve(evidence);
    Console.WriteLine(pState.ToXml().ToString());

    return;
}
' Demonstrate the use of ResolvePolicy for the supplied evidence and a specified policy level.
Private Overloads Shared Sub CheckEvidence(ByVal pLevel As PolicyLevel, ByVal evidence As Evidence)
    ' Display the code groups to which the evidence belongs.
    Console.WriteLine(ControlChars.Tab + "ResolvePolicy for the given evidence: ")
    Dim codeGroup As IEnumerator = evidence.GetEnumerator()
    While codeGroup.MoveNext()
        Console.WriteLine((ControlChars.Tab + ControlChars.Tab + CType(codeGroup.Current, CodeGroup).Name))
    End While
    Console.WriteLine("The current evidence belongs to the following root CodeGroup:")
    ' pLevel is the current PolicyLevel, evidence is the Evidence to be resolved.
    Dim cg1 As CodeGroup = pLevel.ResolveMatchingCodeGroups(evidence)
    Console.WriteLine((pLevel.Label + " Level"))
    Console.WriteLine((ControlChars.Tab + "Root CodeGroup = " + cg1.Name))

    ' Show how Resolve is used to determine the set of permissions that 
    ' the security system grants to code, based on the evidence.
    ' Show the granted permissions. 
    Console.WriteLine(ControlChars.Lf + "Current permissions granted:")
    Dim pState As PolicyStatement = pLevel.Resolve(evidence)
    Console.WriteLine(pState.ToXml().ToString())

    Return
End Sub

注解

Resolve 是策略级别的基本策略评估操作。 在给定一组证据作为输入的情况下,此方法测试代码组的成员身份条件,这些条件从根开始,并按匹配方式向下运行。 匹配代码组产生的权限组合将生成 PolicyStatement 返回的 。

在向代码授予权限时,安全策略对所有适用的策略级别使用已解析的策略语句以及代码权限请求。

适用于