WebRequest.AuthenticationLevel 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,指出用於這個要求的驗證和模擬等級。
public:
property System::Net::Security::AuthenticationLevel AuthenticationLevel { System::Net::Security::AuthenticationLevel get(); void set(System::Net::Security::AuthenticationLevel value); };
public System.Net.Security.AuthenticationLevel AuthenticationLevel { get; set; }
member this.AuthenticationLevel : System.Net.Security.AuthenticationLevel with get, set
Public Property AuthenticationLevel As AuthenticationLevel
屬性值
AuthenticationLevel 值的位元組合。 預設值是 MutualAuthRequested。
在相互驗證中,用戶端和伺服器都會出示建立其識別的認證。 MutualAuthRequired 和 MutualAuthRequested 與 Kerberos 驗證有關。 Kerberos 驗證可以直接支援,或在使用交涉安全性通訊協定時,用來選取實際的安全性通訊協定。 如需驗證通訊協議的詳細資訊,請參閱 因特網驗證。
若要判斷是否發生相互驗證現象,請檢查 IsMutuallyAuthenticated 屬性。
如果您指定 MutualAuthRequired 驗證旗標值,但相互驗證未發生,則應用程式會收到 IOException 以及 ProtocolViolationException 內部例外狀況,指出相互驗證失敗。
範例
下列程式代碼範例會設定此屬性的值。
// 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();
}