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; }
member this.CustomTargetNameDictionary : System.Collections.Specialized.StringDictionary
Public Shared ReadOnly Property CustomTargetNameDictionary As StringDictionary

プロパティ値

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 を追加できます。 このディクショナリに SPN 情報を追加していない場合は、 AuthenticationManager このメソッドを RequestUri 使用して最も可能性の高い SPN を作成します。ただし、これは計算値であり、正しくない可能性があります。 相互認証が試行され、失敗した場合は、ディクショナリを確認して、計算された SPN を確認できます。 認証プロトコルが相互認証をサポートしていない場合、SPN はディクショナリに入力されません。

このディクショナリに SPN 値を追加するには、as キーを使用AbsoluteUriRequestUriします。 内部的には、キーが切り捨てられ、既定のSchemePortポートではない場合は 、Hostキーが含まれます。

注意

のメソッドとプロパティにアクセスするには、無制限WebPermissionCustomTargetNameDictionary必要です。

注意

プロキシ経由で Kerberos 認証を実行する場合は、プロキシと最終的なホスト名の両方を SPN に解決する必要があります。 プロキシ名解決はタイムアウトによって保護されます。 SPN に対する最終的なホスト名の解決には DNS 参照が必要であり、この操作に直接関連付けられているタイムアウトはありません。 そのため、同期操作のタイムアウトに時間がかかる場合があります。 これを回避するには、要求を行う前に、最終的なホストの URI プレフィックスを SPN キャッシュに追加します。

Version 3.5 SP1 の既定では、CustomTargetNameDictionary プロパティが設定されていない場合、NTLM (NT LAN マネージャー) 認証交換の SPN の要求 URL で使用されたホスト名を指定します。 要求 URL で使用されたホスト名は、クライアント要求の System.Net.HttpRequestHeader に指定された Host ヘッダーとは異なる可能性があります。 要求 URL に使用されているホスト名は、サーバーの実際のホスト名、サーバーのコンピューター名、コンピューターの IP アドレス、またはループバック アドレスとは異なる可能性があります。 このような場合、Windows は認証要求に失敗します。 この問題に対処するには、クライアント要求の要求 URL で使用されるホスト名 ("contoso"など) が実際にはローカル コンピューターの代替名であることをWindowsに通知する必要がある場合があります。

適用対象

こちらもご覧ください