2016-06-12 10 views
2

我創建一個Xamarin的WebViewASP.NET MVC5應用程序,但是當我運行模擬器我面臨如下:ERR_Connection Refused 。你能解釋一下如何從Xamarin WebView中調用同一臺機器上的項目嗎?如何調用同一臺機器上自己的ASP.NET MVC項目preaent從xamrin的WebView

protected override void OnCreate(Bundle bundle) 
{ 
    base.OnCreate(bundle); 

    // Set our view from the "main" layout resource 
    SetContentView(Resource.Layout.Main); 

    web_view = FindViewById <WebView> (Resource.Id.webview); 
    web_view.Settings.JavaScriptEnabled = true; 
    web_view.LoadUrl("http://localhost:53183/"); 
} 

回答

0

模擬器中的本地主機將是模擬器本身,而不是您的PC。

更改http://localhost:53183到:

http://:yourpcipaddress53183 

注意:大多數的模擬器還可以映射 「10.0.2.2」 和/或 「10.0.3.2」 作爲您PC的環回適配器。

http://:10.0.2.2:53183 
http://:10.0.3.2:53183 

您可以通過adb測試:

adb shell ping 10.0.2.2 
+0

替換後我變空白頁 – sajiii

+0

您可以使用Android瀏覽器並打開您的網頁嗎? – SushiHangover

+0

我再次面對Android瀏覽器的空白頁面.. – sajiii

0

假設你的本地主機在IIS下運行表現,你需要告訴你的Windows機器接受該網站/端口連接。打開PowerShell中以管理員身份:

netsh http add urlacl url=http://{windows-local-ip}:53183/ user=everyone 

如果你的機器語言不是英語you'll要改變「人人」有相應的翻譯。

然後打開文件applicationhost.config,你可以找到關於YourSolution/.vs/config/applicationhost.config和搜索與您的應用程序的站點節點:

<site name="YourApplication" id="1">...</site> 

內,您可滿足指向到localhost默認<binding>節點。保留原樣,但增加了與您的計算機的本地IP一個新問題:

<binding protocol="http" bindinginformation="*:53183:{local-ip}"></binding> 

例如:

<binding protocol="http" bindinginformation="*:80:192.168.0.57"></binding> 

當您啓動/調試自己的網站,右鍵單擊IIS快遞圖標。您應該看到這樣的事情(本地主機+你的IP:端口):

enter image description here

如果仍然鴕鳥政策看你的ip好像在圖片,重新啓動Visual Studio。

最後,您可能需要在防火牆中打開端口53183。只是爲了確保防火牆不是阻止連接,請停用它並重試。

相關問題