İngilizce dilinde oku

Aracılığıyla paylaş


SocketPermission Sınıf

Tanım

Dikkat

Code Access Security is not supported or honored by the runtime.

Aktarım adresinde bağlantı yapma veya kabul etme haklarını denetler.

C#
[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public sealed class SocketPermission : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
C#
[System.Serializable]
public sealed class SocketPermission : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
C#
public sealed class SocketPermission : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
Devralma
SocketPermission
Öznitelikler
Uygulamalar

Örnekler

Aşağıdaki örnekte, çeşitli yuva erişim kısıtlamalarını ayarlamak, değiştirmek ve zorunlu kılmak için sınıfının nasıl kullanılacağı SocketPermission gösterilmektedir.

C#

     // Creates a SocketPermission restricting access to and from all URIs.
     SocketPermission mySocketPermission1 = new SocketPermission(PermissionState.None);

     // The socket to which this permission will apply will allow connections from www.contoso.com.
     mySocketPermission1.AddPermission(NetworkAccess.Accept, TransportType.Tcp, "www.contoso.com", 11000);

     // Creates a SocketPermission which will allow the target Socket to connect with www.southridgevideo.com.
     SocketPermission mySocketPermission2 =
                                new SocketPermission(NetworkAccess.Connect, TransportType.Tcp, "www.southridgevideo.com", 11002);

     // Creates a SocketPermission from the union of two SocketPermissions.
     SocketPermission mySocketPermissionUnion =
                                (SocketPermission)mySocketPermission1.Union(mySocketPermission2);

     // Checks to see if the union was successfully created by using the IsSubsetOf method.
     if (mySocketPermission1.IsSubsetOf(mySocketPermissionUnion) &&
           mySocketPermission2.IsSubsetOf(mySocketPermissionUnion)){
          Console.WriteLine("This union contains permissions from both mySocketPermission1 and mySocketPermission2");

          // Prints the allowable accept URIs to the console.
          Console.WriteLine("This union accepts connections on :");

          IEnumerator myEnumerator = mySocketPermissionUnion.AcceptList;
       while (myEnumerator.MoveNext()) {
               Console.WriteLine(((EndpointPermission)myEnumerator.Current).ToString());
            }

             // Prints the allowable connect URIs to the console.
          Console.WriteLine("This union permits connections to :");

          myEnumerator = mySocketPermissionUnion.ConnectList;
       while (myEnumerator.MoveNext()) {
               Console.WriteLine(((EndpointPermission)myEnumerator.Current).ToString());
            }
           }


     // Creates a SocketPermission from the intersect of two SocketPermissions.
     SocketPermission mySocketPermissionIntersect =
                               (SocketPermission)mySocketPermission1.Intersect(mySocketPermissionUnion);

     // mySocketPermissionIntersect should now contain the permissions of mySocketPermission1.
     if (mySocketPermission1.IsSubsetOf(mySocketPermissionIntersect)){
          Console.WriteLine("This is expected");
     }
    // mySocketPermissionIntersect should not contain the permissios of mySocketPermission2.
     if (mySocketPermission2.IsSubsetOf(mySocketPermissionIntersect)){
          Console.WriteLine("This should not print");
     }


// Creates a copy of the intersect SocketPermission.
     SocketPermission mySocketPermissionIntersectCopy =
                               (SocketPermission)mySocketPermissionIntersect.Copy();

     if (mySocketPermissionIntersectCopy.Equals(mySocketPermissionIntersect)){
     Console.WriteLine("Copy successfull");
     }


     // Converts a SocketPermission to XML format and then immediately converts it back to a SocketPermission.
     mySocketPermission1.FromXml(mySocketPermission1.ToXml());

     // Checks to see if permission for this socket resource is unrestricted.  If it is, then there is no need to
     // demand that permissions be enforced.
     if (mySocketPermissionUnion.IsUnrestricted()){
        
          //Do nothing.  There are no restrictions.
     }
     else{
         // Enforces the permissions found in mySocketPermissionUnion on any Socket Resources used below this statement.
         mySocketPermissionUnion.Demand();
     }

    IPHostEntry myIpHostEntry = Dns.Resolve("www.contoso.com");
    IPEndPoint myLocalEndPoint = new IPEndPoint(myIpHostEntry.AddressList[0], 11000);

       Socket s = new Socket(myLocalEndPoint.Address.AddressFamily,
                                   SocketType.Stream,
                                         ProtocolType.Tcp);
       try{
            s.Connect(myLocalEndPoint);
       }
       catch (Exception e){
            Console.WriteLine("Exception Thrown: " + e.ToString());
       }

      // Perform all socket operations in here.

      s.Close();

Açıklamalar

Dikkat

Kod Erişim Güvenliği (CAS), .NET Framework ve .NET'in tüm sürümlerinde kullanım dışı bırakılmıştır. .NET'in son sürümleri CAS ek açıklamalarını dikkate almaz ve CAS ile ilgili API'ler kullanılıyorsa hata üretir. Geliştiriciler, güvenlik görevlerini yerine getirmek için alternatif yöntemler aramalıdır.

SocketPermission örnekler, bağlantıları kabul etme veya bağlantıları başlatma Socket iznini denetler. Konak Socket adı veya IP adresi, bağlantı noktası numarası ve aktarım protokolü için izin oluşturulabilir.

Not

Bu adların IP adreslerine çözümlenmesi gerektiğinden, konak adlarını kullanarak yuva izinleri oluşturmaktan kaçının ve bu da yığını engelleyebilir.

Oluşturucular

SocketPermission(NetworkAccess, TransportType, String, Int32)
Geçersiz.

Belirtilen izinle verilen aktarım adresi için sınıfının yeni bir örneğini SocketPermission başlatır.

SocketPermission(PermissionState)
Geçersiz.

öğesine sınırsız erişime Socket izin veren veya erişimine izin veren sınıfının yeni bir örneğini SocketPermissionSocketbaşlatır.

Alanlar

AllPorts
Geçersiz.

Tüm bağlantı noktalarını temsil eden bir sabit tanımlar.

Özellikler

AcceptList
Geçersiz.

Bu izin örneği altında kabul edilebilecek uç noktaları tanımlayan örneklerin listesini EndpointPermission alır.

ConnectList
Geçersiz.

Bu izin örneği altında bağlanabilecek uç noktaları tanımlayan örneklerin listesini EndpointPermission alır.

Yöntemler

AddPermission(NetworkAccess, TransportType, String, Int32)
Geçersiz.

Aktarım adresi için izin kümesine bir izin ekler.

Assert()
Geçersiz.

Yığında daha yüksek arayanlara kaynağa erişim izni verilmemiş olsa bile çağıran kodun bu yöntemi çağıran kod aracılığıyla bir izin talebiyle korunan kaynağa erişebileceğini bildirir. kullanmak Assert() güvenlik sorunları oluşturabilir.

(Devralındığı yer: CodeAccessPermission)
Copy()
Geçersiz.

Örneğin bir kopyasını SocketPermission oluşturur.

Demand()
Geçersiz.

Çağrı yığınında daha yüksek olan tüm arayanlara geçerli örnek tarafından belirtilen izin verilmediyse, çalışma zamanında bir SecurityException zorlar.

(Devralındığı yer: CodeAccessPermission)
Deny()
Geçersiz.
Geçersiz.

Çağrı yığınındaki daha yüksek çağıranların geçerli örnek tarafından belirtilen kaynağa erişmek için bu yöntemi çağıran kodu kullanmasını engeller.

(Devralındığı yer: CodeAccessPermission)
Equals(Object)
Geçersiz.

Belirtilen CodeAccessPermission nesnenin geçerli CodeAccessPermissionöğesine eşit olup olmadığını belirler.

(Devralındığı yer: CodeAccessPermission)
FromXml(SecurityElement)
Geçersiz.

XML kodlaması için bir SocketPermission örneği yeniden oluşturur.

GetHashCode()
Geçersiz.

Karma algoritmalarda ve karma tablo gibi veri yapılarında kullanıma uygun nesne için CodeAccessPermission bir karma kodu alır.

(Devralındığı yer: CodeAccessPermission)
GetType()
Geçersiz.

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

(Devralındığı yer: Object)
Intersect(IPermission)
Geçersiz.

İki SocketPermission örnek arasındaki mantıksal kesişimi döndürür.

IsSubsetOf(IPermission)
Geçersiz.

Geçerli iznin belirtilen iznin bir alt kümesi olup olmadığını belirler.

IsUnrestricted()
Geçersiz.

Nesnenin genel izin durumunu denetler.

MemberwiseClone()
Geçersiz.

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

(Devralındığı yer: Object)
PermitOnly()
Geçersiz.

Çağrı yığınındaki daha yüksek çağıranların geçerli örnek tarafından belirtilen kaynak dışındaki tüm kaynaklara erişmek için bu yöntemi çağıran kodu kullanmasını engeller.

(Devralındığı yer: CodeAccessPermission)
ToString()
Geçersiz.

Geçerli izin nesnesinin dize gösterimini oluşturur ve döndürür.

(Devralındığı yer: CodeAccessPermission)
ToXml()
Geçersiz.

Bir SocketPermission örneğin ve geçerli durumunun XML kodlamasını oluşturur.

Union(IPermission)
Geçersiz.

İki SocketPermission örnek arasındaki mantıksal birleşimi döndürür.

Şunlara uygulanır

Ürün Sürümler (Kullanım dışı)
.NET (8 (package-provided), 9 (package-provided))
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1 (5, 6, 7, 8, 9)