1
我試圖沿着下面的代碼的東西運行在Windows Server 2012 R2機器上的C#的Web客戶端應用程序:權限問題與.NET的Web客戶端應用程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
namespace willitwork
{
class Program
{
static void Main()
{
// Create web client.
WebClient client = new WebClient();
// Download string.
string value = client.DownloadString("http://www.dotnetperls.com/");
// Write values.
Console.WriteLine("--- WebClient result ---");
Console.WriteLine(value.Length);
Console.WriteLine(value);
}
}
}
當我運行應用程序作爲管理員一切工作正常:
C:\moop>whoami
p10uc2\administrator
C:\moop>willitwork.exe
--- WebClient result ---
3336
<!doctype html><html><head><link rel=canonical href=http://www.dotnetperls.com><style>body{font:18px/1.45 verdana;position:relative;padding:0 0 330px;min-width:
750px;max-width:960px;margin:0 auto}...
etc.
但是,部署時,應用程序將由系統啓動。我切換到系統的用戶,並再次運行應用程序,剛要碰到這樣的:
c:\moop>whoami
nt authority\system
c:\moop>willitwork.exe
Unhandled Exception: System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made becaus
e the target machine actively refused it 54.240.176.85:80
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state,
IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadString(Uri address)
at System.Net.WebClient.DownloadString(String address)
at willitwork.Program.Main()
出於某種原因,這似乎並沒有要在Windows 7的問題,我會是什麼任何暗示感激我可能做錯了!