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 は、クライアントが相互認証のためにサーバー上のサービスまたはアプリケーションのインスタンスを一意に識別する名前です。 相互認証は既定で要求され、要求で を にMutualAuthRequired設定WebRequest.AuthenticationLevelすることで要求できます。

WebRequest 相互認証が必要な場合、宛先の SPN をクライアントから提供する必要があります。 SPN がわかっている場合は、要求を送信する前に に CustomTargetNameDictionary 追加できます。 このディクショナリに SPN 情報を追加していない場合、 AuthenticationManager は メソッドを RequestUri 使用して最も可能性の高い SPN を作成します。ただし、これは計算値であり、正しくない可能性があります。 相互認証が試行され、失敗した場合は、ディクショナリをチェックして、計算された SPN を決定できます。 認証プロトコルが相互認証をサポートしていない場合、ディクショナリに SPN は入力されません。

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

注意

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

注意

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 に通知する必要がある場合があります。

適用対象

こちらもご覧ください