共用方式為


NetCodeGroup 類別

定義

授權下載集會的網站。 無法繼承這個類別。

public ref class NetCodeGroup sealed : System::Security::Policy::CodeGroup
public sealed class NetCodeGroup : System.Security.Policy.CodeGroup
[System.Serializable]
public sealed class NetCodeGroup : System.Security.Policy.CodeGroup
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class NetCodeGroup : System.Security.Policy.CodeGroup
type NetCodeGroup = class
    inherit CodeGroup
[<System.Serializable>]
type NetCodeGroup = class
    inherit CodeGroup
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type NetCodeGroup = class
    inherit CodeGroup
Public NotInheritable Class NetCodeGroup
Inherits CodeGroup
繼承
NetCodeGroup
屬性

範例

以下程式碼範例示範如何建立 a NetCodeGroup 並加入 CodeConnectAccess 使用 HTTP 方案下載的程式碼物件。


static void SetNetCodeGroupAccess()
{
    String^ userPolicyLevel = "User";
    // Locate the User policy level.
    PolicyLevel^ level = nullptr;
    System::Collections::IEnumerator^ ph = 
        System::Security::SecurityManager::PolicyHierarchy();
    while(ph->MoveNext())
    {
        level = (PolicyLevel^)ph->Current;
        if (level->Label == userPolicyLevel)
        {
            break;       
        }
    }
    if (level->Label != userPolicyLevel)
        throw gcnew ApplicationException("Could not find User policy level.");

    IMembershipCondition^ membership =
        gcnew UrlMembershipCondition("http://www.contoso.com/*");
    NetCodeGroup^ codeGroup = gcnew NetCodeGroup(membership);
    // Delete default settings.
    codeGroup->ResetConnectAccess();
    // Create an object that represents access to the FTP scheme and 
    // default port.
    CodeConnectAccess^ CodeAccessFtp = 
        gcnew CodeConnectAccess(Uri::UriSchemeFtp, 
        CodeConnectAccess::DefaultPort);
    // Create an object that represents access to the HTTPS scheme 
    // and default port.
    CodeConnectAccess^ CodeAccessHttps = 
        gcnew CodeConnectAccess(Uri::UriSchemeHttps, 
        CodeConnectAccess::DefaultPort);
    // Create an object that represents access to the origin 
    // scheme and port.
    CodeConnectAccess^ CodeAccessOrigin = 
        CodeConnectAccess::CreateOriginSchemeAccess
        (CodeConnectAccess::OriginPort);
    // Add connection access objects to the NetCodeGroup object.
    codeGroup->AddConnectAccess(Uri::UriSchemeHttp, CodeAccessFtp);
    codeGroup->AddConnectAccess(Uri::UriSchemeHttp, CodeAccessHttps);
    codeGroup->AddConnectAccess(Uri::UriSchemeHttp, CodeAccessOrigin);
    // Provide name and description information for caspol.exe tool.
    codeGroup->Name = "ContosoHttpCodeGroup";
    codeGroup->Description = "Code originating from contoso.com can" +
        " connect back using the FTP or HTTPS.";
    // Add the code group to the User policy's root node.
    level->RootCodeGroup->AddChild(codeGroup);
    // Save the changes to the policy level.
    System::Security::SecurityManager::SavePolicy();
}
public static void SetNetCodeGroupAccess()
{
    const string userPolicyLevel = "User";
    // Locate the User policy level.
    PolicyLevel level = null;
    System.Collections.IEnumerator ph =
        System.Security.SecurityManager.PolicyHierarchy();
    while(ph.MoveNext())
    {
        level = (PolicyLevel)ph.Current;
        if( level.Label == userPolicyLevel )
        {
            break;
        }
    }
    if (level.Label != userPolicyLevel)
        throw new ApplicationException("Could not find User policy level.");

    IMembershipCondition membership =
        new UrlMembershipCondition(@"http://www.contoso.com/*");
    NetCodeGroup codeGroup = new NetCodeGroup(membership);
    // Delete default settings.
    codeGroup.ResetConnectAccess();
    // Create an object that represents access to the FTP scheme and default port.
    CodeConnectAccess a1 = new CodeConnectAccess(Uri.UriSchemeFtp, CodeConnectAccess.DefaultPort);
    // Create an object that represents access to the HTTPS scheme and default port.
    CodeConnectAccess a2 = new CodeConnectAccess(Uri.UriSchemeHttps, CodeConnectAccess.DefaultPort);
    // Create an object that represents access to the origin scheme and port.
    CodeConnectAccess a3 = CodeConnectAccess.CreateOriginSchemeAccess(CodeConnectAccess.OriginPort);
    // Add connection access objects to the NetCodeGroup object.
    codeGroup.AddConnectAccess(Uri.UriSchemeHttp, a1);
    codeGroup.AddConnectAccess(Uri.UriSchemeHttp, a2);
    codeGroup.AddConnectAccess(Uri.UriSchemeHttp, a3);
    // Provide name and description information for caspol.exe tool.
    codeGroup.Name = "ContosoHttpCodeGroup";
    codeGroup.Description = "Code originating from contoso.com can connect back using the FTP or HTTPS.";
    // Add the code group to the User policy's root node.
    level.RootCodeGroup.AddChild(codeGroup);
    // Save the changes to the policy level.
    System.Security.SecurityManager.SavePolicy();
}

備註

程式碼群組是程式碼存取安全政策的基石。 每個政策層級由一個根代碼群組組成,該根代碼群組可以包含一個或多個子代碼群組。 每個子程式碼群組可以有自己的子程式碼群組;這種行為可延伸至多個層級,形成一棵樹。 每個代碼群組都有成員條件,根據該組合的證據判斷該組合是否屬於該群組。 只有成員條件與特定組合相符的程式碼群組及其子程式碼群組,才會套用程式碼存取安全政策。

NetCodeGroup具有與 相同的UnionCodeGroup合併語意;它構成了所有匹配子碼群組的物件的聯集PolicyStatement,並由輸入Url證據產生。PolicyStatement 然而,回 NetCodeGroup 傳一個包含動態計算 WebPermission 的權限,該權限授予連線存取執行程式碼所在網站的權限; UnionCodeGroup 簡單來說,則是回傳一個靜態權限集。

當建立 a NetCodeGroup 時,包含下表所示的預設連線存取規則。

URI 協議 規則
檔案 不允許連線到原始伺服器。
http 允許使用原始埠進行 HTTP 和 HTTPS 存取。
https 允許使用原始埠進行 HTTPS 存取。

你可以透過將帶有適當SchemePort屬性值的物件傳CodeConnectAccess給方法,AddConnectAccess來控制該程式碼在回連接原始地點時允許使用的方案和埠碼。 你可以建立一條連線存取規則,當原始方案不在證據中出現或未被識別時,透過指定 AbsentOriginScheme (「」)為該方案來適用。 你也可以建立一條連接存取規則,當沒有連線存取規則且有匹配方案時,透過指定 AnyOtherOriginScheme 「*」作為方案來執行。

備註

若程式碼未提交 URI 方案作為證據,則允許使用任何方案返回原始站點。

建構函式

名稱 Description
NetCodeGroup(IMembershipCondition)

初始化 NetCodeGroup 類別的新執行個體。

欄位

名稱 Description
AbsentOriginScheme

包含一個用來指定來源不明或未識別來源程式的連線存取的值。

AnyOtherOriginScheme

包含一個用來指定任何其他未指定原點方案的值。

屬性

名稱 Description
AttributeString

取得程式碼群組政策語句屬性的字串表示。

Children

取得或設定一個有序的子碼群清單。

(繼承來源 CodeGroup)
Description

取得或設定代碼群組的描述。

(繼承來源 CodeGroup)
MembershipCondition

取得或設定代碼群組的成員條件。

(繼承來源 CodeGroup)
MergeLogic

這就懂了合併群組的邏輯。

Name

取得或設定代碼群組名稱。

(繼承來源 CodeGroup)
PermissionSetName

取得代碼群組的名稱 NamedPermissionSet

PolicyStatement

取得或設定與程式碼群組相關的政策語句。

(繼承來源 CodeGroup)

方法

名稱 Description
AddChild(CodeGroup)

將子程式碼群組加入目前的程式碼群組。

(繼承來源 CodeGroup)
AddConnectAccess(String, CodeConnectAccess)

將指定的連線存取權限加入目前的程式碼群組。

Copy()

會做一個目前程式碼群組的深度複製。

CreateXml(SecurityElement, PolicyLevel)

當在派生類別中覆寫時,序列化了特定於衍生程式碼群組的屬性與內部狀態,並將序列化加入指定的 SecurityElement

(繼承來源 CodeGroup)
Equals(CodeGroup, Boolean)

判斷指定的代碼組是否等同於目前代碼組,並在指定時檢查子代碼組。

(繼承來源 CodeGroup)
Equals(Object)

判斷指定的代碼組是否等同於目前代碼組。

Equals(Object)

判斷指定的代碼組是否等同於目前代碼組。

(繼承來源 CodeGroup)
FromXml(SecurityElement, PolicyLevel)

從 XML 編碼重建具有特定狀態與政策層級的安全物件。

(繼承來源 CodeGroup)
FromXml(SecurityElement)

從 XML 編碼重建具有特定狀態的安全物件。

(繼承來源 CodeGroup)
GetConnectAccessRules()

取得目前代碼群組的連線存取資訊。

GetHashCode()

取得目前程式碼群組的雜湊碼。

GetHashCode()

取得目前程式碼群組的雜湊碼。

(繼承來源 CodeGroup)
GetType()

取得目前實例的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ParseXml(SecurityElement, PolicyLevel)

當在派生類別中覆寫時,會從指定的 SecurityElement中重建導出程式碼群組特有的屬性與內部狀態。

(繼承來源 CodeGroup)
RemoveChild(CodeGroup)

移除指定的子程式碼群組。

(繼承來源 CodeGroup)
ResetConnectAccess()

移除目前代碼群組的所有連線存取資訊。

Resolve(Evidence)

解決代碼群組及其後代的政策,針對一組證據。

ResolveMatchingCodeGroups(Evidence)

解析匹配的程式碼群組。

ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)
ToXml()

建立安全物件及其當前狀態的 XML 編碼。

(繼承來源 CodeGroup)
ToXml(PolicyLevel)

建立安全物件、其當前狀態及程式碼所屬政策層級的 XML 編碼。

(繼承來源 CodeGroup)

適用於