AuthenticationManager.CustomTargetNameDictionary Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene il dizionario che contiene i nomi dell'entità servizio (SPN) utilizzati per identificare gli host durante l'autenticazione Kerberos per le richieste effettuate utilizzando WebRequest e le relative classi derivate.
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
Valore della proprietà
Oggetto scrivibile StringDictionary che contiene i valori SPN per le chiavi composte da informazioni sull'host.
Esempio
Nell'esempio di codice seguente viene illustrato come visualizzare il contenuto di CustomTargetNameDictionary.
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>
*/
Commenti
Un nome SPN è un nome in base al quale un client identifica in modo univoco un'istanza di un servizio o di un'applicazione in un server ai fini dell'autenticazione reciproca. L'autenticazione reciproca è richiesta per impostazione predefinita ed è possibile richiederla impostando WebRequest.AuthenticationLevel su MutualAuthRequired nella richiesta.
Quando un oggetto WebRequest richiede l'autenticazione reciproca, il nome SPN per la destinazione deve essere fornito dal client. Se si conosce il nome SPN, è possibile aggiungerlo a CustomTargetNameDictionary prima di inviare la richiesta. Se non sono state aggiunte informazioni SPN a questo dizionario, AuthenticationManager usa il metodo per comporre il RequestUri nome SPN più probabile. Tuttavia, si tratta di un valore calcolato e potrebbe non essere corretto. Se si tenta di eseguire l'autenticazione reciproca e non riesce, è possibile controllare il dizionario per determinare il nome SPN calcolato. Non viene immesso alcun nome SPN nel dizionario se il protocollo di autenticazione non supporta l'autenticazione reciproca.
Per aggiungere un valore SPN a questo dizionario, usare l'oggetto AbsoluteUriRequestUri di come chiave. Internamente, la chiave viene troncata per includere Scheme, Hoste se Port non è la porta predefinita.
Annotazioni
L'accesso ai metodi e alle proprietà di richiede un numero illimitato WebPermissiondi CustomTargetNameDictionary .
Annotazioni
Quando l'autenticazione Kerberos viene eseguita tramite un proxy, sia il proxy che il nome host finale devono essere risolti in un nome SPN. La risoluzione dei nomi proxy è protetta da un timeout. La risoluzione del nome host finale a un nome SPN richiede una ricerca DNS e non esiste alcun timeout associato direttamente a questa operazione. Di conseguenza, le operazioni sincrone potrebbero richiedere più tempo per il timeout. Per ovviare a questo problema, aggiungere il prefisso URI dell'host finale alla cache SPN prima di effettuare richieste.
Per impostazione predefinita, la versione 3.5 SP1 specifica il nome host usato nell'URL della richiesta nel nome SPN nello scambio di autenticazione NTLM (NT LAN Manager) quando la CustomTargetNameDictionary proprietà non è impostata. Il nome host usato nell'URL della richiesta può essere diverso dall'intestazione host specificata nella System.Net.HttpRequestHeader richiesta client. Il nome host usato nell'URL della richiesta può essere diverso dal nome host effettivo del server, dal nome del computer del server, dall'indirizzo IP del computer o dall'indirizzo di loopback. In questi casi, Windows non riuscirà a eseguire la richiesta di autenticazione. Per risolvere il problema, potrebbe essere necessario notificare a Windows che il nome host usato nell'URL della richiesta del client ("contoso", ad esempio) è in realtà un nome alternativo per il computer locale.