NetCodeGroup 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
授權下載集會的網站。 無法繼承這個類別。
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
- 繼承
- 屬性
範例
以下程式碼範例示範如何建立 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 存取。 |
你可以透過將帶有適當Scheme且Port屬性值的物件傳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) |