Bagikan melalui


NetworkOperatorTetheringAccessPointConfiguration.IsAuthenticationKindSupportedAsync Metode

Definisi

Secara asinkron mengambil nilai yang menunjukkan apakah adaptor Wi-Fi memungkinkan konfigurasi titik akses dengan jenis autentikasi tertentu.

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)

Parameter

authenticationKind
TetheringWiFiAuthenticationKind

Nilai enumerasi TetheringWiFiAuthenticationKind , menentukan jenis autentikasi untuk dikueri.

Mengembalikan

Objek operasi asinkron yang, ketika selesai, berisi true jika jenis autentikasi didukung; jika tidak, false.

Atribut

Persyaratan Windows

Rangkaian perangkat
Windows 11 Insider Preview (diperkenalkan dalam 10.0.26100.0)
API contract
Windows.Foundation.UniversalApiContract (diperkenalkan dalam v19.0)
Kemampuan aplikasi
wiFiControl

Contoh

Contoh kode di bawah ini mencantumkan dua metode publik: untuk mengatur pita dan jenis autentikasi untuk koneksi tethering. Ada juga contoh metode privat untuk mengambil konfigurasi tethering saat ini dari koneksi internet aktif pada komputer. Objek konfigurasi tethering berisi properti jenis pita dan autentikasi yang sedang diatur, dan ini adalah parameter utama untuk API ConfigureAccessPointAsync yang digunakan untuk menerapkan perubahan.

Di Utama, beberapa baris kode pertama mengatur band (menggunakan nilai 6 GHz, jika tersedia). Perhatikan juga penggunaan kelas ApiInformation untuk memeriksa apakah jenis autentikasi tertentu didukung. Setelah itu, kode mengatur jenis autentikasi. Kode ini menunjukkan penggunaan nilai enumerasi dari TetheringWiFiBand dan TetheringWiFiAuthenticationKind.

Dalam metode publik SetBandForWiFiAccessPointAsync dan SetAuthenticationKindForWiFiAccessPointAsync, kode menampilkan hal berikut:

  • Mengambil konfigurasi AP untuk koneksi internet aktif pada komputer.
  • Memperbarui properti jenis pita dan autentikasi pada objek konfigurasi (NetworkOperatorTetheringAccessPointConfiguration).
  • Menerapkan konfigurasi yang diperbarui, dan mengembalikan konfigurasi yang berhasil diterapkan (atau null jika terjadi kegagalan).
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);
        }
    }
}

Berlaku untuk