WebResponse.IsMutuallyAuthenticated Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient une valeur Boolean indiquant si l'authentification mutuelle s'est produite.
public:
virtual property bool IsMutuallyAuthenticated { bool get(); };
public virtual bool IsMutuallyAuthenticated { get; }
member this.IsMutuallyAuthenticated : bool
Public Overridable ReadOnly Property IsMutuallyAuthenticated As Boolean
Valeur de propriété
true
si le client et le serveur ont tous les deux été authentifiés ; sinon, false
.
Exemples
L’exemple de code suivant vérifie la valeur de cette propriété.
// The following example uses the System, System.Net,
// and System.IO namespaces.
static void RequestMutualAuth( Uri^ resource )
{
// Create a new HttpWebRequest object for the specified resource.
WebRequest^ request = dynamic_cast<WebRequest^>(WebRequest::Create( resource ));
// Request mutual authentication.
request->AuthenticationLevel = AuthenticationLevel::MutualAuthRequested;
// Supply client credentials.
request->Credentials = CredentialCache::DefaultCredentials;
HttpWebResponse^ response = dynamic_cast<HttpWebResponse^>(request->GetResponse());
// Determine whether mutual authentication was used.
Console::WriteLine( L"Is mutually authenticated? {0}", response->IsMutuallyAuthenticated );
// Read and display the response.
Stream^ streamResponse = response->GetResponseStream();
StreamReader^ streamRead = gcnew StreamReader( streamResponse );
String^ responseString = streamRead->ReadToEnd();
Console::WriteLine( responseString );
// Close the stream objects.
streamResponse->Close();
streamRead->Close();
// Release the HttpWebResponse.
response->Close();
}
// The following example uses the System, System.Net,
// and System.IO namespaces.
public static void RequestMutualAuth(Uri resource)
{
// Create a new HttpWebRequest object for the specified resource.
WebRequest request=(WebRequest) WebRequest.Create(resource);
// Request mutual authentication.
request.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested;
// Supply client credentials.
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
// Determine whether mutual authentication was used.
Console.WriteLine("Is mutually authenticated? {0}", response.IsMutuallyAuthenticated);
// Read and display the response.
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string responseString = streamRead.ReadToEnd();
Console.WriteLine(responseString);
// Close the stream objects.
streamResponse.Close();
streamRead.Close();
// Release the HttpWebResponse.
response.Close();
}
Remarques
Pour demander l’authentification mutuelle, définissez la propriété à l’aide WebRequest.AuthenticationLevel de la valeur d’énumération MutualAuthRequested ou MutualAuthRequired . La valeur par défaut de la propriété WebRequest.AuthenticationLevel contient Delegation et MutualAuthRequested.
Notez que l’obtention de cette propriété peut lever ObjectDisposedException.