Condividi tramite


NetworkOperatorTetheringAccessPointConfiguration.IsAuthenticationKindSupportedAsync Metodo

Definizione

Recupera in modo asincrono un valore che indica se l'adattatore Wi-Fi consente di configurare il punto di accesso con un tipo di autenticazione specifico.

public:
 virtual IAsyncOperation<bool> ^ IsAuthenticationKindSupportedAsync(TetheringWiFiAuthenticationKind authenticationKind) = IsAuthenticationKindSupportedAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<bool> IsAuthenticationKindSupportedAsync(TetheringWiFiAuthenticationKind const& authenticationKind);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<bool> IsAuthenticationKindSupportedAsync(TetheringWiFiAuthenticationKind authenticationKind);
function isAuthenticationKindSupportedAsync(authenticationKind)
Public Function IsAuthenticationKindSupportedAsync (authenticationKind As TetheringWiFiAuthenticationKind) As IAsyncOperation(Of Boolean)

Parametri

authenticationKind
TetheringWiFiAuthenticationKind

Valore di enumerazione TetheringWiFiAuthenticationKind , specificando il tipo di autenticazione su cui eseguire una query.

Restituisce

Oggetto operazione asincrona che, al termine, contiene true se il tipo di autenticazione è supportato; in caso contrario, false.

Attributi

Requisiti Windows

Famiglia di dispositivi
Windows 11 Insider Preview (è stato introdotto in 10.0.26100.0)
API contract
Windows.Foundation.UniversalApiContract (è stato introdotto in v19.0)
Funzionalità dell'app
wiFiControl

Esempio

L'esempio di codice seguente elenca due metodi pubblici: per impostare la banda e il tipo di autenticazione per una connessione di tethering. Esiste anche un metodo privato di esempio per recuperare la configurazione corrente del tethering della connessione Internet attiva nel computer. L'oggetto di configurazione del tethering contiene le proprietà del tipo di banda e di autenticazione che vengono impostate ed è l'unico parametro per l'API ConfigureAccessPointAsync usata per applicare le modifiche.

In Main, le prime righe di codice impostano la banda (usando il valore 6 GHz, se disponibile). Si noti anche l'uso della classe ApiInformation per verificare se è supportato un particolare tipo di autenticazione. Successivamente, il codice imposta il tipo di autenticazione. Questo codice illustra l'uso dei valori di enumerazione di TetheringWiFiBand e TetheringWiFiAuthenticationKind.

Nei metodi pubblici SetBandForWiFiAccessPointAsync e SetAuthenticationKindForWiFiAccessPointAsync, il codice presenta quanto segue:

  • Recupero della configurazione AP per la connessione Internet attiva nel computer.
  • Aggiornamento delle proprietà del tipo di banda e di autenticazione nell'oggetto di configurazione (NetworkOperatorTetheringAccessPointConfiguration).
  • Applicazione della configurazione aggiornata e restituzione della configurazione applicata correttamente (o null in caso di errore).
using System;
using System.Threading.Tasks;
using Windows.Foundation.Metadata;
using Windows.Networking.NetworkOperators;
using Windows.Networking.Connectivity;

namespace DemoApp
{
    class DemoClass
    {
        private static NetworkOperatorTetheringAccessPointConfiguration GetCurrentAPConfig()
        {
            // Get the connection profile associated with the internet connection currently used by the local machine.
            ConnectionProfile currentConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
            if (currentConnectionProfile == null)
            {
                throw new InvalidOperationException("Machine isn't connected to the internet.");
            }

            NetworkOperatorTetheringManager tetheringManager =
                NetworkOperatorTetheringManager.CreateFromConnectionProfile(currentConnectionProfile);

            NetworkOperatorTetheringAccessPointConfiguration configuration =
                tetheringManager.GetCurrentAccessPointConfiguration();

            return configuration;
        }

        public static async Task<NetworkOperatorTetheringAccessPointConfiguration>
            SetBandForWiFiAccessPointAsync(TetheringWiFiBand wifiBand)
        {
            NetworkOperatorTetheringAccessPointConfiguration configuration = GetCurrentAPConfig();

            if (!await configuration.IsBandSupportedAsync(wifiBand))
            {
                throw new ArgumentException("Band parameter isn't supported on AP.");
            }

            configuration.Band = wifiBand;

            try
            {
                await tetheringManager.ConfigureAccessPointAsync(configuration);

                return configuration;
            }
            catch
            {
                return null;
            }
        }

        public static async Task<NetworkOperatorTetheringAccessPointConfiguration>
            SetAuthenticationKindForWiFiAccessPointAsync(TetheringWiFiAuthenticationKind wiFiAuthenticationKind)
        {
            if (!ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 16))
            {
                throw new InvalidOperationException("OS doesn't support configuring auth.");
            }

            NetworkOperatorTetheringAccessPointConfiguration configuration = GetCurrentAPConfig();

            if (!await configuration.IsAuthenticationKindSupportedAsync(wiFiAuthenticationKind))
            {
                throw new ArgumentException("Authentication kind parameter isn't supported on AP.");
            }

            configuration.AuthenticationKind = wiFiAuthenticationKind;

            try
            {
                await tetheringManager.ConfigureAccessPointAsync(configuration);

                return configuration;
            }
            catch
            {
                return null;
            }
        }

        public static void Main()
        {
            NetworkOperatorTetheringAccessPointConfiguration sampleResult1 = null;
            if (ApiInformation.IsEnumNamedValuePresent(
                "Windows.Networking.NetworkOperators.TetheringWiFiBand", "SixGigahertz"))
            {
                sampleResult1 = await SetBandForWiFiAccessPointAsync(TetheringWiFiBand.SixGigahertz);
            }
            else
            {
                sampleResult1 = await SetBandForWiFiAccessPointAsync(TetheringWiFiBand.FiveGigahertz);
            }

            NetworkOperatorTetheringAccessPointConfiguration sampleResult2 =
                await SetAuthenticationKindForWiFiAccessPointAsync(TetheringWiFiAuthenticationKind.Wpa3);
        }
    }
}

Si applica a