AuthenticationManager.CustomTargetNameDictionary Propiedad

Definición

Obtiene el diccionario que contiene los Nombres de entidad de seguridad de servicio (SPN) utilizados para identificar los hosts durante la autenticación Kerberos para las solicitudes realizadas utilizando WebRequest y sus clases derivadas.

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

Valor de propiedad

Un objeto StringDictionary en el que se puede escribir que contiene los valores SPN para las claves compuestas de información de host.

Ejemplos

En el ejemplo de código siguiente se muestra el contenido de 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>

*/

Comentarios

Un SPN es un nombre por el que un cliente identifica de forma única una instancia de un servicio o una aplicación en un servidor con fines de autenticación mutua. La autenticación mutua se solicita de forma predeterminada y puede requerirla estableciendo WebRequest.AuthenticationLevelMutualAuthRequired en en la solicitud.

Cuando se WebRequest requiere autenticación mutua, el cliente debe proporcionar el SPN para el destino. Si conoce el SPN, puede agregarlo a CustomTargetNameDictionary antes de enviar la solicitud. Si no ha agregado información de SPN a este diccionario, usa AuthenticationManager el método para componer el RequestUri SPN más probable; sin embargo, se trata de un valor calculado y podría ser incorrecto. Si se intenta realizar la autenticación mutua y se produce un error, puede comprobar el diccionario para determinar el SPN calculado. No se introduce ningún SPN en el diccionario si el protocolo de autenticación no admite la autenticación mutua.

Para agregar un valor SPN a este diccionario, use el AbsoluteUri de RequestUri como clave. Internamente, la clave se trunca para incluir , SchemeHosty si Port no es el puerto predeterminado.

Nota

El acceso a los métodos y propiedades de requiere CustomTargetNameDictionary unrestricted WebPermission.

Nota

Cuando la autenticación Kerberos se realiza a través de un proxy, tanto el proxy como el nombre de host final deben resolverse en un SPN. La resolución de nombres de proxy está protegida por un tiempo de espera. La resolución del nombre de host final a un SPN requiere una búsqueda de DNS y no hay tiempo de espera asociado directamente a esta operación. Por lo tanto, las operaciones sincrónicas pueden tardar más tiempo en expirar. Para superar esto, agregue el prefijo URI del host final a la memoria caché de SPN antes de realizar solicitudes a él.

Ahora el comportamiento predeterminado de SP1 versión 3.5 es especificar el nombre de host usado en la dirección URL de solicitud del SPN en el intercambio de autenticación NTLM (NT LAN Manager) cuando la propiedad CustomTargetNameDictionary no está establecida. El nombre de host usado en la dirección URL de solicitud puede ser diferente al encabezado de host especificado en System.Net.HttpRequestHeader en la solicitud de cliente. El nombre de host usado en la dirección URL de solicitud puede ser diferente al nombre de host real del servidor, el nombre de equipo del servidor, la dirección IP del equipo o la dirección de bucle invertido. En estos casos se produce un error en la solicitud de autenticación de Windows. Para solucionar el problema, es posible que tenga que notificar a Windows que el nombre de host usado en la dirección URL de solicitud en la solicitud de cliente ("contoso", por ejemplo) es realmente un nombre alternativo para el equipo local.

Se aplica a

Consulte también