AuthenticationLevel Перечисление

Определение

Определяет клиентские требования проверки подлинности и олицетворения при использовании класса WebRequest и производных от него классов для запроса ресурса.

public enum class AuthenticationLevel
public enum AuthenticationLevel
type AuthenticationLevel = 
Public Enum AuthenticationLevel
Наследование
AuthenticationLevel

Поля

MutualAuthRequested 1

Клиент и сервер должны пройти проверку подлинности. Запрос не завершается неудачно, если сервер не прошел проверку подлинности. Чтобы определить, произошла ли взаимная проверка подлинности, следует проверить значение свойства IsMutuallyAuthenticated.

MutualAuthRequired 2

Клиент и сервер должны пройти проверку подлинности. Если сервер не прошел проверку подлинности, приложение получит IOException с внутренним исключением ProtocolViolationException, указывающим на неудачное завершение взаимной проверки подлинности.

None 0

Для клиента и для сервера проверка подлинности не требуется.

Примеры

В следующем примере кода показано задание флагов проверки подлинности для запроса.

// 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();
}

Комментарии

Значения этого перечисления используются для задания AuthenticationLevel свойства.

Примечание

Значения MutualAuthRequired и MutualAuthRequested относятся к проверке подлинности Kerberos. Проверка подлинности по протоколу Kerberos может поддерживаться напрямую или использоваться, если для выбора фактического протокола безопасности применяется протокол безопасности Negotiate. Дополнительные сведения о протоколах проверки подлинности см. в разделе "Проверка подлинности в Интернете".

Применяется к