NetCodeGroup(IMembershipCondition) Costruttore
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Inizializza una nuova istanza della classe NetCodeGroup.
public:
NetCodeGroup(System::Security::Policy::IMembershipCondition ^ membershipCondition);
public NetCodeGroup (System.Security.Policy.IMembershipCondition membershipCondition);
new System.Security.Policy.NetCodeGroup : System.Security.Policy.IMembershipCondition -> System.Security.Policy.NetCodeGroup
Public Sub New (membershipCondition As IMembershipCondition)
Parametri
- membershipCondition
- IMembershipCondition
Condizione di appartenenza in base alla quale viene verificata l'evidenza per determinare se questo gruppo di codice consente di applicare i criteri di sicurezza per l' accesso.
Eccezioni
Il valore del parametro membershipCondition
è null
.
Il tipo del parametro membershipCondition
non è valido.
Esempio
L'esempio di codice seguente illustra la creazione di oggetti NetCodeGroup e l'aggiunta CodeConnectAccess di oggetti per il codice scaricato usando lo schema 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();
}
Commenti
Quando viene creato un oggetto NetCodeGroup , contiene le regole di accesso alla connessione predefinite visualizzate nella tabella seguente.
Schema | Regola |
---|---|
file | Non è consentito l'accesso alla connessione al server di origine. |
http | L'accesso HTTP e HTTPS è consentito usando la porta di origine. |
https | L'accesso HTTPS è consentito usando la porta di origine. |