【问题标题】:Why UWP function AddProfileFromObjectAsync() throws exeption?为什么 UWP 函数 Add Profile FromObject Async() 会抛出异常?
【发布时间】:2019-11-01 08:44:44
【问题描述】:

我正在尝试使用 UWP 创建 VPN 连接,但当它运行时,我从 AddProfileFromObjectAsync() exception message 收到异常。

auto  mgr = ref new VpnManagementAgent();
auto  profile = ref new VpnNativeProfile();

profile->AlwaysOn               = false;
profile->NativeProtocolType     = VpnNativeProtocolType::L2tp;
profile->ProfileName            = "TestVpn";
profile->RememberCredentials    = true;
profile->RequireVpnClientAppUI  = true;
profile->RoutingPolicyType      = VpnRoutingPolicyType::ForceAllTrafficOverVpn;
profile->TunnelAuthenticationMethod = VpnAuthenticationMethod::PresharedKey;
profile->UserAuthenticationMethod   = VpnAuthenticationMethod::Mschapv2;
profile->Servers->Append("45.87.213.134");

auto profileStatus = mgr->AddProfileFromObjectAsync(profile);

【问题讨论】:

  • “访问被拒绝”通常会试图告诉您您忘记在 appx 清单中请求该功能。
  • @Hans Passant,告诉我怎么做或清单中的哪些地方是必要的参数?

标签: uwp vpn c++-cx


【解决方案1】:

从这个document,它提到如果你想使用 VpnManagementAgent 类,你需要添加 networkingVpnProvider 能力。 networkVpnProvider 功能允许应用完全访问 VPN 功能,包括管理连接和提供 VPN 插件功能的能力。您可以像下面这样添加它:

.appxmanifest:

<Package ...... 
     xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" 
     IgnorableNamespaces="uap mp rescap">

     ......

<rescap:Capability Name="networkingVpnProvider" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-28
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多