WebResponse.IsMutuallyAuthenticated Propriedade
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
true
se o cliente e o servidor foram autenticados; caso contrário, false
.
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();
}
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.
Produto | Versões |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
Comentários do .NET
O .NET é um projeto código aberto. Selecione um link para fornecer comentários: