WebResponse.IsMutuallyAuthenticated 属性
定义
public:
virtual property bool IsMutuallyAuthenticated { bool get(); };
public virtual bool IsMutuallyAuthenticated { get; }
member this.IsMutuallyAuthenticated : bool
Public Overridable ReadOnly Property IsMutuallyAuthenticated As Boolean
属性值
如果客户端和服务器均经过验证,则为 true;否则为 false。true if both client and server were authenticated; otherwise, false.
示例
下面的代码示例检查此属性的值。The following code example checks the value of this property.
// 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();
}
注解
若要请求相互身份验证,请 WebRequest.AuthenticationLevel 使用 MutualAuthRequested 或 MutualAuthRequired 枚举值设置属性。To request mutual authentication, set the WebRequest.AuthenticationLevel property using the MutualAuthRequested or MutualAuthRequired enumeration value. 属性的默认值 WebRequest.AuthenticationLevel 包含 Delegation 和 MutualAuthRequested 。The default value for the WebRequest.AuthenticationLevel property contains Delegation and MutualAuthRequested.
请注意,获取此属性可能会引发 ObjectDisposedException 。Note that getting this property can throw ObjectDisposedException.