Share via


AuthenticationManager.CustomTargetNameDictionary 속성

정의

WebRequest와 이 클래스의 파생 클래스를 통한 요청에 대해 Kerberos 인증을 수행하는 동안 호스트를 식별하는 데 사용되는 SPN(서비스 사용자 이름)이 들어 있는 사전을 가져옵니다.

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

속성 값

호스트 정보로 구성된 키에 대한 SPN 값이 들어 있는 쓰기 가능한 StringDictionary입니다.

예제

다음 코드 예제에서는 의 내용을 표시 합니다 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>

*/

설명

SPN에 클라이언트를 고유 하 게 식별 하는 서비스 또는 상호 인증을 위해 서버에서 애플리케이션 인스턴스의 이름입니다. 상호 인증은 기본적으로 요청되며 요청에서 를 로 설정 WebRequest.AuthenticationLevelMutualAuthRequired 하여 요구할 수 있습니다.

WebRequest 상호 인증이 필요한 경우 대상에 대한 SPN을 클라이언트에서 제공해야 합니다. SPN을 알고 있는 경우 요청을 보내기 전에 에 CustomTargetNameDictionary 추가할 수 있습니다. 이 사전에 SPN 정보를 추가하지 않은 경우 는 AuthenticationManager 메서드를 RequestUri 사용하여 가장 가능성이 높은 SPN을 작성합니다. 그러나 이는 계산된 값이며 올바르지 않을 수 있습니다. 상호 인증이 시도되고 실패하는 경우 사전을 검사 계산된 SPN을 확인할 수 있습니다. 인증 프로토콜이 상호 인증을 지원하지 않는 경우 사전에 SPN이 입력되지 않습니다.

이 사전에 SPN 값을 추가하려면 의 RequestUriAbsoluteUri 키로 사용합니다. 내부적으로 키는 기본 포트가 아닌 경우 , HostPort 을 포함Scheme하도록 잘립니다.

참고

CustomTargetNameDictionary 메서드 및 속성에 액세스하려면 무제한 WebPermission이 필요합니다.

참고

프록시를 통해 Kerberos 인증을 수행하는 경우 프록시 및 최종 호스트 이름을 SPN으로 확인해야 합니다. 프록시 이름 확인은 시간 제한으로 보호됩니다. SPN에 대한 최종 호스트 이름을 확인하려면 DNS 조회가 필요하며 이 작업과 직접 연결된 시간 제한이 없습니다. 따라서 동기 작업은 시간 초과에 더 오래 걸릴 수 있습니다. 이를 해결하려면 요청하기 전에 SPN 캐시에 궁극적인 호스트의 URI 접두사를 추가합니다.

이제 버전 3.5 SP1에서는 CustomTargetNameDictionary 속성이 설정되지 않은 경우 NTLM(NT LAN Manager) 인증 교환에서 SPN의 요청 URL에 사용된 호스트 이름을 지정하도록 기본적으로 설정됩니다. 요청 URL에 사용된 호스트 이름은 클라이언트 요청의 System.Net.HttpRequestHeader에 지정된 호스트 헤더와 다를 수 있습니다. 요청 URL에 사용된 호스트 이름은 서버의 실제 호스트 이름, 서버의 컴퓨터 이름, 컴퓨터의 IP 주소 또는 루프백 주소와 다를 수 있습니다. 이 경우 Windows가 인증 요청에 실패합니다. 이 문제를 해결하려면 클라이언트 요청의 요청 URL에 사용되는 호스트 이름(예: "contoso")이 실제로 로컬 컴퓨터의 대체 이름임을 Windows에 알려야 할 수 있습니다.

적용 대상

추가 정보