2010-02-02 122 views
0

我有一個ASP MVC控制器操作。 我試圖做一個Web請求ASP - 在本地主機上運行 - 無法訪問互聯網

public ActionResult Index() 
{ 
    WebRequest request = HttpWebRequest.Create("http://www.example.com"); 
    WebResponse response = request.GetResponse(); 
    string str = response.ToString(); 
}` 

我得到一個「引發WebException發生」遠程名稱無法解析:「www.example.com」

如果我開始提琴手,那麼網絡請求的作品。

我嘗試添加:

<system.net> 
<defaultProxy> 
    <proxy usesystemdefault ="True" bypassonlocal="True" /> 
</defaultProxy> 

到Web.config中(有和沒有興田bypassonlocal),它仍然無法正常工作。

有什麼建議嗎?

回答

0

嘗試指定代理服務器明確:

<system.net> 
    <defaultProxy> 
     <proxy proxyaddress="http://proxy.yourcompany.com:80" /> 
    </defaultProxy> 
</system.net> 

您還可以設置編程代理:

request.Proxy = new WebProxy("http://proxy.yourcompany.com:80", true); 

當您設置usesystemdefaulttrue,應用程序使用在Internet Options對話框中定義的代理框。在IIS中部署應用程序時,通常在具有非常有限特權的Network Service帳戶下執行,它甚至沒有任何GUI會話,因此無法推斷代理服務器。

相關問題