Search code examples
c#uwpvpnuwp-xaml

UWP Vpn AddProfileFromObjectAsync always return "other" error


I'm trying to create a new VPN profile in a universal windows app. I am using this API.

public async void connect()
        {
            var connectionProfile = new VpnNativeProfile
            {
                AlwaysOn = true,
                NativeProtocolType = VpnNativeProtocolType.IpsecIkev2,
                ProfileName = "TestProfile",
                RememberCredentials = true,
                RequireVpnClientAppUI = true,
                RoutingPolicyType = VpnRoutingPolicyType.ForceAllTrafficOverVpn,
                UserAuthenticationMethod = VpnAuthenticationMethod.Eap,
                TunnelAuthenticationMethod = VpnAuthenticationMethod.Eap,
            };

            connectionProfile.Servers.Add("192.168.1.123");

            var credential = new PasswordCredential
            {
                UserName = "test",
                Password = "test123"
            };

            var status = await windowsVpnManager.AddProfileFromObjectAsync(connectionProfile);

            Debug.Print($"Connection status -> {status}");
        }

But this code always return status "other", if i create vpn profile from setting with a same properties, it work.


Solution

  • Peter Smith has already answered this issue on Microsoft Q&A here:https://learn.microsoft.com/en-us/answers/questions/1155880/uwp-vpn-addprofilefromobjectasync-always-return-ot

    I will post a summary about the solution here as well.

    Answer from Perter:

    Please add the EapConfiguration node for your profile. More information is listed here: VPNv2CSP.

    In the description of VPNv2/ProfileName/NativeProfile/Authentication/Eap it mentions that the Eap node is required; the only actual required item is the Eap/Configuration. There are steps for making a sample Eap configuration at EAP Configuration.

    The code should be something like this:

    connectionProfile.EapConfiguration = "<EapHostConfig xmlns=........ (long string removed)";