WebResponse.IsMutuallyAuthenticated Propriedade
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém um valor Boolean que indica se ocorreu uma autenticação mútua.
public:
virtual property bool IsMutuallyAuthenticated { bool get(); };
public virtual bool IsMutuallyAuthenticated { get; }
member this.IsMutuallyAuthenticated : bool
Public Overridable ReadOnly Property IsMutuallyAuthenticated As Boolean
Valor da propriedade
true
se o cliente e o servidor foram autenticados; caso contrário, false
.
Exemplos
O exemplo de código a seguir verifica o valor dessa propriedade.
// 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();
}
Comentários
Para solicitar autenticação mútua, defina a WebRequest.AuthenticationLevel propriedade usando o MutualAuthRequested valor de enumeração ou MutualAuthRequired . O valor padrão da WebRequest.AuthenticationLevel propriedade contém Delegation e MutualAuthRequested.
Observe que obter essa propriedade pode gerar ObjectDisposedException.