PolicyLevel.Resolve(Evidence) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
依據原則層級的辨識項 (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
用來解析 Evidence 的 PolicyLevel。
傳回
結果為 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 傳回的 。
在授與程式代碼許可權時,安全策略會針對所有適用的原則層級使用已解析的原則語句,以及許可權的程序代碼要求。