Здравствуйте, я работаю над VPN в C#, это мой код
VpnManagementAgent vpnManagementAgent = new VpnManagementAgent();
VpnManagementAgent mgr = vpnManagementAgent;
VpnNativeProfile profile = new VpnNativeProfile()
{
AlwaysOn = false,
NativeProtocolType = VpnNativeProtocolType.IpsecIkev2,
ProfileName = "MyConnection",
RememberCredentials = true,
RequireVpnClientAppUI = true,
RoutingPolicyType = VpnRoutingPolicyType.SplitRouting,
TunnelAuthenticationMethod = VpnAuthenticationMethod.Certificate,
UserAuthenticationMethod = VpnAuthenticationMethod.Mschapv2,
};
profile.Servers.Add("serveAddress");
VpnManagementErrorStatus profileStatus = await mgr.AddProfileFromObjectAsync(profile);
PasswordCredential credentials = new PasswordCredential
{
UserName = "username",
Password = "Abc",
};
VpnManagementErrorStatus connectStatus = await mgr.ConnectProfileWithPasswordCredentialAsync(profile, credentials);
Я добавляю весь этот код при нажатии кнопки. теперь, когда я запускаю VPN-соединение, эта строка выдает исключение
VpnManagementErrorStatus profileStatus = await mgr.AddProfileFromObjectAsync(profile);
Exception is
System.UnauthorizedAccessException: 'Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))'
StackTrace:
at Windows.Networking.Vpn.VpnManagementAgent.AddProfileFromObjectAsync(IVpnProfile profile)
at App1.MainPage.<Button_Click>d__2.MoveNext() in C:\Users\HP\source\repos\StarkVPnTesting\App1\MainPage.xaml.cs:line 62