首页 > 解决方案 > 如何解决 C# 中的 VPN 连接错误

问题描述

我在我的程序中使用了一个 VPN 类。但是当我尝试连接时,会导致以下错误:

系统找不到此连接的电话簿条目

这是连接方法:

public void VPN_Connect(string VPN_Name, string VPN_ID, string VPN_PW)
{
    string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Network\Connections\Pbk\rasphone.pbk";
    AllUsersPhoneBook = new RasPhoneBook();
    AllUsersPhoneBook.Open(path);

    if (AllUsersPhoneBook.Entries.Contains(EntryName))
    {
        AllUsersPhoneBook.Entries[EntryName].PhoneNumber = VPN_Name;
        AllUsersPhoneBook.Entries[EntryName].Update();
    }
    else
    {
        RasEntry entry = RasEntry.CreateVpnEntry(EntryName, VPN_Name, RasVpnStrategy.Default,
                        RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn));

        entry.EncryptionType = RasEncryptionType.None;

        AllUsersPhoneBook.Entries.Add(entry);
    }

    Dialer = new RasDialer();
    Dialer.DialCompleted += new EventHandler<DialCompletedEventArgs>(Dialer_DialCompleted);

    this.Dialer.EntryName = EntryName;
    this.Dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers);

    try
    {
        this.Dialer.Credentials = new NetworkCredential(VPN_ID, VPN_PW);
        this.handle = this.Dialer.DialAsync();
        VPN_Status = (int)status.Defalut;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

我怎么解决这个问题?

我还在使用带有最新更新和 DotRas 最新版本的 Windows 10。

标签: c#vpn

解决方案


推荐阅读