NetCodeGroup-Klasse
Erteilt Webberechtigung für die Site, aus der die Assembly gedownloadet wurde. Diese Klasse kann nicht vererbt werden.
Namespace: System.Security.Policy
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class NetCodeGroup
Inherits CodeGroup
'Usage
Dim instance As NetCodeGroup
[SerializableAttribute]
[ComVisibleAttribute(true)]
public sealed class NetCodeGroup : CodeGroup
[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class NetCodeGroup sealed : public CodeGroup
/** @attribute SerializableAttribute() */
/** @attribute ComVisibleAttribute(true) */
public final class NetCodeGroup extends CodeGroup
SerializableAttribute
ComVisibleAttribute(true)
public final class NetCodeGroup extends CodeGroup
Hinweise
Codegruppen sind die Bausteine der Sicherheitsrichtlinien für den Codezugriff. Jede Richtlinienebene besteht aus einer Stammcodegruppe, die eine oder mehrere untergeordnete Codegruppen enthalten kann. Jede untergeordnete Codegruppe kann über eigene untergeordnete Codegruppen verfügen, wodurch eine Baumstruktur mit einer beliebigen Anzahl von Ebenen entsteht. Jede Codegruppe verfügt über eine Mitgliedschaftsbedingung, die anhand der Beweise für eine angegebene Assembly bestimmt, ob diese zur Codegruppe gehört. Nur Codegruppen, deren Mitgliedschaftsbedingungen einer angegebenen Assembly entsprechen, und ihre untergeordneten Codegruppen wenden Sicherheitsrichtlinien für den Codezugriff an.
NetCodeGroup hat dieselbe Zusammenführungssemantik wie UnionCodeGroup und bildet die Gesamtmenge der PolicyStatement-Objekte aller übereinstimmenden untergeordneten Codegruppen und dem PolicyStatement, das aus dem eingegebenen Url-Beweis generiert wird. NetCodeGroup gibt jedoch eine Berechtigung mit einer dynamisch berechneten WebPermission zurück, die den Verbindungszugriff auf die Site ermöglicht, in der der Code ausgeführt wird. UnionCodeGroup gibt lediglich einen statischen Berechtigungssatz zurück.
Wenn eine NetCodeGroup erstellt wird, enthält sie die in folgender Tabelle aufgeführten Standardregeln für den Verbindungszugriff.
URI-Schema |
Regel |
---|---|
file |
Es ist kein Verbindungszugriff auf den ursprünglichen Server zulässig. |
http |
Der HTTP- und HTTPS-Zugriff mit dem ursprünglichen Port ist zulässig. |
https |
Der HTTPS-Zugriff mit dem ursprünglichen Port ist zulässig. |
Sie können bestimmen, welches Schema und welchen Port Code beim Herstellen einer Rückverbindung mit der Ursprungssite verwenden kann, indem Sie ein CodeConnectAccess-Objekt mit dem entsprechenden Scheme-Eigenschaftenwert und Port-Eigenschaftenwert an die AddConnectAccess-Methode übergeben. Sie können eine Verbindungszugriffsregel erstellen, die angewendet wird, wenn das Ursprungsschema nicht im Beweis vorhanden ist oder nicht erkannt wird, indem Sie AbsentOriginScheme ("") als Schema angeben. Sie können außerdem eine Verbindungszugriffsregel erstellen, die angewendet wird, wenn keine Verbindungszugriffsregel mit einem entsprechenden Schema vorhanden ist, indem Sie AnyOtherOriginScheme ("*") als Schema angeben.
Hinweis
Wenn durch den Code kein URI-Schema als Beweis bereitgestellt wird, wird der Zugriff auf die Ursprungssite mit einem beliebigen Schema gewährt.
Beispiel
Im folgenden Codebeispiel wird veranschaulicht, wie eine NetCodeGroup erstellt und CodeConnectAccess-Objekte für Code hinzugefügt werden, die mit dem HTTP-Schema gedownloadet wurden.
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(@"https://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();
}
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("https://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() throws ApplicationException
{
final 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.get_Current();
if (level.get_Label().Equals(userPolicyLevel)) {
break;
}
}
if (!(level.get_Label().Equals(userPolicyLevel))) {
throw new ApplicationException("Could not find User policy level.");
}
IMembershipCondition membership =
new UrlMembershipCondition("https://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.set_Name("ContosoHttpCodeGroup");
codeGroup.set_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.get_RootCodeGroup().AddChild(codeGroup);
// Save the changes to the policy level.
System.Security.SecurityManager.SavePolicy();
} //SetNetCodeGroupAccess
Vererbungshierarchie
System.Object
System.Security.Policy.CodeGroup
System.Security.Policy.NetCodeGroup
Threadsicherheit
Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.
Plattformen
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
NetCodeGroup-Member
System.Security.Policy-Namespace