[英]Can't dial with DotRas in Windows Server 2012 R2
我對DotRas完全陌生,所以請耐心等待。我配置了“路由和遠程訪問”的Windows Server 2012 R2。 在這種簡單的配置中,您可以在第一張圖片中看到與VPN的撥號器連接。
因此,如果我單擊connect ..一切正常,並且網絡接口的狀態從斷開變為已連接。 去事件查看器,這就是我得到的:
來自RASCLIENT源日志的事件:
事件1:
CoId={A52088DC-5358-44D6-8B77-DA49516C3FBD}: The user SYSTEM has started dialing a VPN connection using a all-user connection profile named VpnAtlanta02. The connection settings are:
Dial-in User = c******s
VpnStrategy = PPTP
DataEncryption = Require
PrerequisiteEntry =
AutoLogon = No
UseRasCredentials = Yes
Authentication Type = MS-CHAPv2
Ipv4DefaultGateway = No
Ipv4AddressAssignment = By Server
Ipv4DNSServerAssignment = By Server
Ipv6DefaultGateway = Yes
Ipv6AddressAssignment = By Server
Ipv6DNSServerAssignment = By Server
IpDnsFlags =
IpNBTEnabled = No
UseFlags = Private Connection
ConnectOnWinlogon = No.
事件2:
CoId={A52088DC-5358-44D6-8B77-DA49516C3FBD}: The user SYSTEM is trying to establish a link to the Remote Access Server for the connection named VpnAtlanta02 using the following device:
Server address/Phone Number = ***.***.***.***
Device = WAN Miniport (PPTP)
Port = VPN3-4
MediaType = VPN.
事件3:
CoId={A52088DC-5358-44D6-8B77-DA49516C3FBD}: The user SYSTEM has successfully established a link to the Remote Access Server using the following device:
Server address/Phone Number = ***.***.***.***
Device = WAN Miniport (PPTP)
Port = VPN3-4
MediaType = VPN.
事件4:
CoId={A52088DC-5358-44D6-8B77-DA49516C3FBD}: The link to the Remote Access Server has been established by user SYSTEM.
事件5:
CoId={A52088DC-5358-44D6-8B77-DA49516C3FBD}: The user SYSTEM has dialed a connection named VpnAtlanta02 to the Remote Access Server which has successfully connected. The connection parameters are:
TunnelIpAddress = 172.20.0.19
TunnelIpv6Address = None
Dial-in User = c******s.
現在..我的目標是從Windows服務建立連接
這是我的代碼(關鍵部分):
Dialer = new RasDialer();
Dialer.PhoneBookPath = "C:\\Windows\\System32\\ras\\Router.pbk";
Dialer.Timeout = 20 * 1000;
Dialer.HangUpPollingInterval = 20 * 1000;
Dialer.AllowUseStoredCredentials = false;
Dialer.AutoUpdateCredentials = RasUpdateCredential.None;
Dialer.EntryName = "VpnAtlanta02";
Dialer.Credentials = new System.Net.NetworkCredential("c******s", "*********");
Watcher = new RasConnectionWatcher();
Watcher.EnableRaisingEvents = true;
Watcher.Connected += Watcher_Connected;
Watcher.Disconnected += Watcher_Disconnected;
InfoLog("Begin connection");
Watcher.Handle = Dialer.Dial();
private void Watcher_Disconnected(object sender, RasConnectionEventArgs e)
{
InfoLog(e.Connection.EntryName + " is disconnected");
}
private void Watcher_Connected(object sender, RasConnectionEventArgs e)
{
InfoLog(e.Connection.EntryName + " is connected");
}
Sofar,無論如何...轉到事件查看器以尋找RasClient事件源,正如預期的那樣,我記錄了5個事件。 1,2,3和4等於手動連接生成的數字,不幸的是最后一個(5)為:
CoId={E2814072-13C7-44CF-998A-A1160FDC86E3}: The user SYSTEM dialed a connection named VpnAtlanta02 which has failed. The error code returned on failure is 720.
請考慮一下,如果您認為憑據有誤或其他。.我完全沒有憑據就做了嘗試,在這種情況下,我無法獲得事件4的任何想法?
首先第一件事! 這不是我的問題的答案 ,但是...我認為這對遇到相同麻煩的任何人都可能有幫助。
經過一堆嘗試甚至嘗試使用DotRas源代碼進行調試之后,我沒有前進任何步伐,此外,我不確定這是否可以完成。 我說是因為嘗試從管理員命令提示符下使用“ rasdial”命令,所以我得到了相同的結果:失敗,錯誤代碼為720。這表示我已經使用Powershell解決方案。
我一直在尋找3個功能強大的cmdlet
-獲取-VpnS2SInterface-連接-VpnS2SInterface-斷開-VpnS2SInterface
所以我只設置了3種簡單的方法,現在一切都像一個魅力
public Boolean IsConnected()
{
Boolean retVal = false;
using (PowerShell ps = PowerShell.Create())
{
ps.AddCommand("Get-VpnS2SInterface");
ps.AddParameter("Name", "VpnAtlanta02");
foreach (PSObject result in ps.Invoke())
{
retVal = ("" + result.Members["ConnectionState"].Value).ToLower() == "connected";
}
}
return retVal;
}
public void Connect()
{
using (PowerShell ps = PowerShell.Create())
{
ps.AddCommand("Connect-VpnS2SInterface");
ps.AddParameter("Name", "VpnAtlanta02");
ps.AddParameter("PassThru");
foreach (PSObject result in ps.Invoke())
{
String destination = "";
foreach (String s in result.Members["Destination"].Value as String[])
{
destination += "{" + s + "}";
}
Service1.InfoLog("Destination=" + destination + "\r\n" +
"ConnectionState=" + result.Members["ConnectionState"].Value + "\r\n");
}
}
}
public void Disconnect()
{
using (PowerShell ps = PowerShell.Create())
{
ps.AddCommand("Disconnect-VpnS2SInterface");
ps.AddParameter("Name", "VpnAtlanta02");
ps.AddParameter("Force");
ps.Invoke();
Service1.InfoLog("Nic: " + "VpnAtlanta02" + " is connected: " + IsConnected());
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.