Aracılığıyla paylaş


CodeConnectAccess Sınıf

Tanım

Koda verilen ağ kaynağı erişimini belirtir.

public ref class CodeConnectAccess
public class CodeConnectAccess
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeConnectAccess
type CodeConnectAccess = class
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeConnectAccess = class
Public Class CodeConnectAccess
Devralma
CodeConnectAccess
Öznitelikler

Örnekler

Aşağıdaki kod örneği bir NetCodeGroup nesne oluşturur ve bunu Kullanıcı ilkesi düzeyine ekler.


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();
}

Açıklamalar

Bu sınıf, yürütme kodunun NetCodeGroup indirildiği siteye nasıl geri bağlanabileceğini denetlemek için sınıfıyla birlikte kullanılır. Bu sınıflar, kodun WebPermission kaynak sitesine erişmek için hangi düzenleri ve bağlantı noktalarını kullanabileceğini denetleen kod yürütmeye verilen için programlı denetim sağlar. Kodun kaynaklandığı URL'deki şemaya göre izin verilen düzen ve bağlantı noktası çiftleri belirtebilirsiniz.

Kodun kaynak şemasını temel alan bir CodeConnectAccess nesne oluşturmak için yöntemini kullanın CreateOriginSchemeAccess .

Herhangi bir düzen kullanabilen ancak bağlantı noktasıyla kısıtlanmış bir CodeConnectAccess nesne oluşturmak için yöntemini kullanın CreateAnySchemeAccess .

Oluşturucular

CodeConnectAccess(String, Int32)

CodeConnectAccess sınıfının yeni bir örneğini başlatır.

Alanlar

AnyScheme

Şema joker karakterlerini temsil eden dize değerini içerir.

DefaultPort

Varsayılan bağlantı noktasını temsil etmek için kullanılan değeri içerir.

OriginPort

Kodun kaynaklandığı URI'de bağlantı noktası değerini temsil etmek için kullanılan değeri içerir.

OriginScheme

Kodun kaynaklandığı URL'de düzeni temsil etmek için kullanılan değeri içerir.

Özellikler

Port

Geçerli örnek tarafından temsil edilen bağlantı noktasını alır.

Scheme

Geçerli örnek tarafından temsil edilen URI düzenini alır.

Yöntemler

CreateAnySchemeAccess(Int32)

Herhangi bir düzen kullanarak belirtilen bağlantı noktasına erişimi temsil eden bir CodeConnectAccess örnek döndürür.

CreateOriginSchemeAccess(Int32)

Kodun kaynak şemasını kullanarak belirtilen bağlantı noktasına erişimi temsil eden bir CodeConnectAccess örnek döndürür.

Equals(Object)

İki CodeConnectAccess nesnenin aynı şemayı ve bağlantı noktasını temsil edip etmediğini belirten bir değer döndürür.

GetHashCode()

Belirli bir tür için karma işlevi olarak görev yapar.

GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır