c# - 如何从 xamrin webview 调用同一台机器上的你自己的 ASP.NET MVC 项目

标签 c# android asp.net-mvc xamarin webview

我正在为 ASP.NET MVC5 应用程序创建一个 Xamarin WebView,但是当我运行模拟器时,我遇到了以下问题:ERR_Connection Refused。你能解释一下如何从 Xamarin 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/");
}

最佳答案

模拟器中的本地主机将是模拟器本身,而不是您的 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

关于c# - 如何从 xamrin webview 调用同一台机器上的你自己的 ASP.NET MVC 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37772966/

相关文章:

c# - UserPrincipal.GetGroups 与 UserPrincipal.GetAuthorizationGroups?

c# - 发生 System.TypeInitializationException

asp.net - asp.net mvc 3 有什么新功能?

c# - 仅营业时间内 DateTime 之间的 TimeSpan 8 :30am - 5:00pm M-F

c# - 将 [Authorize] 属性与用户的电子邮件一起使用

android - 在 Intent fragment 上获取可序列化的 ArrayList

c# - ExecuteCore() vs OnActionExecuting(ActionExecutingContext filterContext)?

.net - 将字符串添加到请求的 URL

android - Azure 通知中心出现错误,并出现NotificationHubUnauthorizedException : Unauthorized in Android client

android - ADB与Android App通信方式