AuthenticationLevel Enumeration

Namespace: System.Net.Security

Assembly: System (in System.dll)

Syntax

public enum AuthenticationLevel

Remarks

The AuthenticationLevel enumeration specifies the level of authentication required for network resources. This enumeration is used by the System.Net.Security.NegotiateStream class and other security-related classes to determine the authentication requirements when establishing a secure communication channel.

It allows developers to control the trade-off between security and performance by choosing an appropriate authentication level for their specific application needs.

Members

The AuthenticationLevel enumeration has the following members:

MutualAuthentication

Specifies that mutual authentication is required. Both the client and the server must authenticate themselves to each other.

MutualAuthentication

None

Specifies that no authentication is required. This is the least secure option and should only be used in trusted environments.

None

WindowsTransport

Specifies that Windows integrated authentication is used. This typically relies on the operating system's authentication mechanisms (e.g., Kerberos or NTLM) to authenticate the client to the server.

WindowsTransport

Example

The following code example demonstrates how to set the AuthenticationLevel when creating a NegotiateStream object.

using System;
using System.Net.Security;
using System.Net.Sockets;

public class Example
{
    public static void Main(string[] args)
    {
        try
        {
            TcpClient client = new TcpClient("server.example.com", 8080);
            NetworkStream stream = client.GetStream();

            // Use WindowsTransport for authentication
            NegotiateStream ns = new NegotiateStream(stream, true);
            ns.AuthenticateAsClient(CredentialCache.DefaultCredentials, 
                                    ProtectionLevel.EncryptAndSign, 
                                    AuthenticationLevel.WindowsTransport);

            Console.WriteLine("Client authenticated successfully.");

            // ... perform secure communication ...

            ns.Close();
            client.Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine("Authentication failed: " + ex.Message);
        }
    }
}

Requirements

Namespace: `System.Net.Security`

Assembly: `System` (in `System.dll`)