英文:
UWP Vpn AddProfileFromObjectAsync always return "other" error
问题
我正在尝试在通用 Windows 应用程序中创建一个新的 VPN 配置文件。我正在使用 这个 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}");
}
但是这段代码总是返回状态 "other",如果我使用相同的属性从设置中创建 VPN 配置文件,它就能工作。
英文:
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.
答案1
得分: 0
Peter Smith已经在Microsoft Q&A上回答了这个问题,链接在这里:https://learn.microsoft.com/en-us/answers/questions/1155880/uwp-vpn-addprofilefromobjectasync-always-return-ot
我也会在这里发布关于解决方案的摘要。
Peter的回答:
请为您的配置文件添加EapConfiguration节点。更多信息请参考这里:VPNv2CSP。
在VPNv2/ProfileName/NativeProfile/Authentication/Eap的描述中提到Eap节点是必需的;实际上唯一必需的项是Eap/Configuration。有关创建示例Eap配置的步骤,请参考EAP配置。
代码应该类似于:
connectionProfile.EapConfiguration = "<EapHostConfig xmlns=........(省略了很长的字符串)";
英文:
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)";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论