+-
C#-UWP创建VPN连接
目前,我正在尝试弄清楚如何添加VPN配置文件并从通用应用程序连接到它.我可以使用 Windows.Networking.Vpn命名空间连接到现有的VPN连接.我还可以添加一个配置文件,但找不到设置所有必需信息的方法(例如PSK). MS文档中没有有关此名称空间的文档.我还看到有两种不同的配置文件名称空间可用:VpnNativeProfile和VpnPlugInProfile.它们之间有什么区别?目前我不在家,所以我无法提供当前代码,但是如果有人可以给我一些提示,这将非常有帮助.在其他地方有可用的文档吗?

编辑1 //
这是我的示例代码

建立个人资料

VpnManagementAgent mgr = new VpnManagementAgent();

VpnNativeProfile profile = new VpnNativeProfile()
{
    AlwaysOn = false,
    NativeProtocolType = VpnNativeProtocolType.L2tp,
    ProfileName = "MyConnection",
    RememberCredentials = true,
    RequireVpnClientAppUI = true,
    RoutingPolicyType = VpnRoutingPolicyType.SplitRouting,
    TunnelAuthenticationMethod = VpnAuthenticationMethod.PresharedKey,
    UserAuthenticationMethod = VpnAuthenticationMethod.Mschapv2,
};

profile.Servers.Add("vpn.example.com");

VpnManagementErrorStatus profileStatus = await mgr.AddProfileFromObjectAsync(profile);

连接到VPN

PasswordCredential credentials = new PasswordCredential
{
    UserName = "username",
    Password = "password",
};

VpnManagementErrorStatus connectStatus = await mgr.ConnectProfileWithPasswordCredentialAsync(profile, credentials);

这可行,但是我不知道在哪里或如何设置PSK.

最佳答案
VPN本机配置文件:这是指Windows收件箱/内置VPN配置文件,可用于基于L2TP,PPTP或IKEv2的VPN

VPN插件配置文件:指的是基于Windows 10 UWP的VPN插件.这是使用Windows.networking.VPN命名空间编写的VPN应用程序.

我也看了一眼代码,可以看到似乎有一个非常明显的遗漏,那就是实际上没有办法通过代码设置PSK.唯一真正的解决方法是暂时在“设置” UI中进行设置.

我将继续向Windows的VPN小组报告有关此问题的丢失.

文档链接:https://docs.microsoft.com/en-us/uwp/api/windows.networking.vpn

点击查看更多相关文章

转载注明原文:C#-UWP创建VPN连接 - 乐贴网