Bagikan melalui


AuthenticationManager.CustomTargetNameDictionary Properti

Definisi

Mendapatkan kamus yang berisi Nama Prinsipal Layanan (SPN) yang digunakan untuk mengidentifikasi host selama autentikasi Kerberos untuk permintaan yang dibuat menggunakan WebRequest dan kelas turunannya.

public:
 static property System::Collections::Specialized::StringDictionary ^ CustomTargetNameDictionary { System::Collections::Specialized::StringDictionary ^ get(); };
public static System.Collections.Specialized.StringDictionary CustomTargetNameDictionary { get; }
static member CustomTargetNameDictionary : System.Collections.Specialized.StringDictionary
Public Shared ReadOnly Property CustomTargetNameDictionary As StringDictionary

Nilai Properti

Bisa-tulis StringDictionary yang berisi nilai SPN untuk kunci yang terdiri dari informasi host.

Contoh

Contoh kode berikut menunjukkan menampilkan konten CustomTargetNameDictionary.

static void RequestResource( Uri^ resource )
{
   // Set policy to send credentials when using HTTPS and basic authentication.
   // Create a new HttpWebRequest object for the specified resource.
   WebRequest^ request = dynamic_cast<WebRequest^>(WebRequest::Create( resource ));

   // Supply client credentials for basic authentication.
   request->UseDefaultCredentials = true;
   request->AuthenticationLevel = AuthenticationLevel::MutualAuthRequired;
   HttpWebResponse^ response = dynamic_cast<HttpWebResponse^>(request->GetResponse());

   // Determine mutual authentication was used.
   Console::WriteLine( L"Is mutually authenticated? {0}", response->IsMutuallyAuthenticated );
   System::Collections::Specialized::StringDictionary^ spnDictionary = AuthenticationManager::CustomTargetNameDictionary;
   System::Collections::IEnumerator^ myEnum = spnDictionary->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      DictionaryEntry^ e = safe_cast<DictionaryEntry^>(myEnum->Current);
      Console::WriteLine( "Key: {0}  - {1}", dynamic_cast<String^>(e->Key), dynamic_cast<String^>(e->Value) );
   }

   // Read and display the response.
   System::IO::Stream^ streamResponse = response->GetResponseStream();
   System::IO::StreamReader^ streamRead = gcnew System::IO::StreamReader( streamResponse );
   String^ responseString = streamRead->ReadToEnd();
   Console::WriteLine( responseString );

   // Close the stream objects.
   streamResponse->Close();
   streamRead->Close();

   // Release the HttpWebResponse.
   response->Close();
}

/*

The output from this example will differ based on the requested resource
and whether mutual authentication was successful. For the purpose of illustration,
a sample of the output is shown here:

Is mutually authenticated? True
Key: http://server1.someDomain.contoso.com  - HTTP/server1.someDomain.contoso.com

<html>
...
</html>

*/
       public static void RequestResource(Uri resource)
        {
            // Set policy to send credentials when using HTTPS and basic authentication.

            // Create a new HttpWebRequest object for the specified resource.
            WebRequest request=(WebRequest) WebRequest.Create(resource);
            // Supply client credentials for basic authentication.
            request.UseDefaultCredentials = true;
            request.AuthenticationLevel = AuthenticationLevel.MutualAuthRequired;
            HttpWebResponse response = (HttpWebResponse) request.GetResponse();
            // Determine mutual authentication was used.
            Console.WriteLine("Is mutually authenticated? {0}", response.IsMutuallyAuthenticated);

             System.Collections.Specialized.StringDictionary spnDictionary = AuthenticationManager.CustomTargetNameDictionary;
            foreach (System.Collections.DictionaryEntry e in spnDictionary)
            {
                Console.WriteLine("Key: {0}  - {1}", e.Key as string, e.Value as string);
            }
            // Read and display the response.
            System.IO.Stream streamResponse = response.GetResponseStream();
            System.IO.StreamReader streamRead = new System.IO.StreamReader(streamResponse);
            string responseString = streamRead.ReadToEnd();
            Console.WriteLine(responseString);
            // Close the stream objects.
            streamResponse.Close();
            streamRead.Close();
            // Release the HttpWebResponse.
            response.Close();
        }

/*

The output from this example will differ based on the requested resource
and whether mutual authentication was successful. For the purpose of illustration,
a sample of the output is shown here:

Is mutually authenticated? True
Key: http://server1.someDomain.contoso.com  - HTTP/server1.someDomain.contoso.com

<html>
...
</html>

*/

Keterangan

SPN adalah nama di mana klien secara unik mengidentifikasi instans layanan atau aplikasi di server untuk tujuan autentikasi bersama. Autentikasi timbal balik diminta secara default, dan Anda dapat mewajibkannya dengan mengatur WebRequest.AuthenticationLevel ke MutualAuthRequired dalam permintaan Anda.

Ketika memerlukan WebRequest autentikasi timbal balik, SPN untuk tujuan harus disediakan oleh klien. Jika Anda mengetahui SPN, Anda dapat menambahkannya ke CustomTargetNameDictionary sebelum mengirim permintaan. Jika Anda belum menambahkan informasi SPN ke kamus RequestUri ini, AuthenticationManager menggunakan metode untuk menyusun SPN yang paling mungkin; namun, ini adalah nilai komputasi dan mungkin salah. Jika autentikasi timbal balik dicoba dan gagal, Anda dapat memeriksa kamus untuk menentukan SPN komputasi. Tidak ada SPN yang dimasukkan ke dalam kamus jika protokol autentikasi tidak mendukung autentikasi timbal balik.

Untuk menambahkan nilai SPN ke kamus ini, gunakan AbsoluteUri dari RequestUri sebagai kunci. Secara internal, kunci dipotong untuk menyertakan Scheme, , Hostdan Port jika bukan port default.

Catatan

Mengakses metode dan properti CustomTargetNameDictionary dari memerlukan tidak terbatas WebPermission.

Catatan

Ketika autentikasi Kerberos dilakukan melalui proksi, proksi dan nama host utama perlu diselesaikan ke SPN. Resolusi nama proksi dilindungi oleh batas waktu. Resolusi nama host utama ke SPN memerlukan pencarian DNS, dan tidak ada batas waktu yang terkait langsung dengan operasi ini. Oleh karena itu, operasi sinkron mungkin membutuhkan waktu lebih lama untuk waktu habis. Untuk mengatasinya, tambahkan awalan URI host utama ke cache SPN sebelum membuat permintaan ke dalamnya.

Versi 3.5 SP1 sekarang default untuk menentukan nama host yang digunakan dalam URL permintaan di SPN di pertukaran autentikasi NTLM (NT LAN Manager) ketika properti CustomTargetNameDictionary tidak diatur. Nama host yang digunakan dalam URL permintaan mungkin berbeda dari header Host yang ditentukan dalam System.Net.HttpRequestHeader permintaan klien. Nama host yang digunakan dalam URL permintaan mungkin berbeda dari nama host server yang sebenarnya, nama mesin server, alamat IP komputer, atau alamat putaran balik. Dalam kasus ini, Windows akan gagal dalam permintaan autentikasi. Untuk mengatasi masalah ini, Anda mungkin perlu memberi tahu Windows bahwa nama host yang digunakan dalam URL permintaan dalam permintaan klien ("contoso", misalnya) sebenarnya adalah nama alternatif untuk komputer lokal.

Berlaku untuk

Lihat juga