NetCodeGroup 類別

定義

將 Web 使用權限授權給下載組件的來源站台。 此類別無法獲得繼承。

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
屬性

範例

下列程式碼範例示範如何為使用 HTTP 配置下載的程式碼建立 NetCodeGroup 和新增 CodeConnectAccess 物件。


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 ,以及 PolicyStatement 它從輸入 Url 辨識項產生的 。 不過, NetCodeGroup 傳回包含動態計算 WebPermission 的許可權,授與執行程式碼之月臺的連線存取權; UnionCodeGroup 只要傳回靜態許可權集合即可。

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

URI 配置 規則
檔案 不允許對源伺服器的連線存取。
http 允許使用原始埠進行 HTTP 和 HTTPS 存取。
https 使用源埠允許 HTTPS 存取。

您可以藉由將具有適當 Scheme 和 屬性值 AddConnectAccess 的物件傳遞 CodeConnectAccess 至 方法,來控制程式代碼在連接到其原點時,允許使用的配置和 Port 埠。 您可以建立連線存取規則,當來源配置不存在於辨識項中,或指定 (「」) 作為配置來辨識 AbsentOriginScheme 。 您也可以藉由指定 AnyOtherOriginScheme (「*」) 做為配置,建立沒有連線存取規則時套用的連接存取規則。

注意

如果程式碼未將 URI 配置提交為辨識項,則允許使用任何配置回到源網站。

建構函式

NetCodeGroup(IMembershipCondition)

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

欄位

AbsentOriginScheme

包含用來指定程式碼 (具有未知或無法辨認之原始配置) 連接存取的值。

AnyOtherOriginScheme

包含用來指定任何其他未指定原始配置的值。

屬性

AttributeString

取得程式碼群組之原則陳述式屬性 (Attribute) 的字串表示。

Children

取得或設定程式碼群組的子程式碼群組之排序清單。

(繼承來源 CodeGroup)
Description

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

(繼承來源 CodeGroup)
MembershipCondition

取得或設定程式碼群組的成員資格條件。

(繼承來源 CodeGroup)
MergeLogic

取得用於合併群組的邏輯。

Name

取得或設定程式碼群組的名稱。

(繼承來源 CodeGroup)
PermissionSetName

取得用於程式碼群組的 NamedPermissionSet 名稱。

PolicyStatement

取得或設定與程式碼群組相關的原則陳述式。

(繼承來源 CodeGroup)

方法

AddChild(CodeGroup)

加入子程式碼群組到目前程式碼群組。

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

將指定的連接存取加入至目前的程式碼群組。

Copy()

製作目前程式碼群組的深層複本 (Deep Copy)。

CreateXml(SecurityElement, PolicyLevel)

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

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

判斷指定的程式碼群組是否等於目前程式碼群組,若有指定則檢查子程式碼群組。

(繼承來源 CodeGroup)
Equals(Object)

判斷指定的程式碼群組是否相等於目前程式碼群組。

Equals(Object)

判斷指定的程式碼群組是否相等於目前程式碼群組。

(繼承來源 CodeGroup)
FromXml(SecurityElement)

使用 XML 編碼方式重建具有指定狀態的安全性物件。

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

使用 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)

適用於