目前我正在尝试解决一个问题,即如何在我的通用应用程序中添加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。
win-universal-app
标签应与所使用的操作系统(Windows 8.1 或 Windows 10)结合使用。 - Manfred RadlwimmerWindows.Networking.Vpn
命名空间才能访问它。 - andy