【发布时间】:2018-04-27 02:38:12
【问题描述】:
目前我正在尝试弄清楚如何添加 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。
【问题讨论】:
-
win-universal-app标签应与使用的操作系统(Windows 8.1 或 Windows 10)结合使用。 -
用示例代码编辑了问题。
-
我运行了您的代码,但它并没有在我这边创建新的连接。我在 Connections 中看不到任何内容(在 Windows 10 中)。基本上,这个 Native Profile 只允许你将你的 UWP 应用程序连接到 VPN?或者它允许您通过 VPN 路由来自整个计算机的全部流量?
-
对不起,这是我的错,您必须设置“RequireVpnClientAppUI = true”才能看到连接。不,它应该允许通过 VPN 的所有流量路由,但您也可以使用带有“RoutingPolicyType”设置的拆分隧道。
-
好的,谢谢您的回答。在我这边,当我尝试连接时,VpnManagementErrorStatus 设置为“其他”。你也遇到同样的错误吗?
标签: c# uwp win-universal-app vpn