Android 模拟器环回 IIS Express 不起作用,但可以与 Cassini 一起使用

发布于 2024-11-13 05:55:38 字数 300 浏览 4 评论 0原文

我正在尝试将本地计算机上 Android 模拟器中运行的 Android 应用程序中的数据发布到也在本地计算机上运行的 IIS Express 下运行的 Web 应用程序。不幸的是,当我从模拟器发布到 10.0.2.2 时,我收到一条 Host Not Found 错误消息。

如果我将 Web 应用程序配置为在 ASP.NET Dev Server (Cassini) 而不是 IIS Express 下运行,则 Android 应用程序能够正常发布。我缺少 IIS Express 的哪些配置,导致它无法使用 Android 模拟器的环回?

I am attempting to post data from an Android application running in the Android Emulator on my local machine to a web application running under IIS Express also running on my local machine. Unfortunately, when I post to 10.0.2.2 from the emulator I receive a Host Not Found error message.

If I configure the web application to run under ASP.NET Dev Server (Cassini) instead of IIS Express the Android application is able to post with no problems. What configuration am I missing for IIS Express that is preventing it from working with a loopback from the Android emulator?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

独守阴晴ぅ圆缺 2024-11-20 05:55:38

授予您自己绑定到 localhost 以外的网络适配器的权限,并将 IIS Express 配置为绑定到所有适配器。

然后,IIS Express 将通过 10.0.2.2 接受来自 Android 模拟器的连接。如果向防火墙添加规则,还可以将 IIS Express 暴露到网络,这会降低安全性,但对于测试物理设备很有用。

步骤详细信息:(假设端口号为 5555 - 请使用您的实际端口)

  1. 以管理员身份从命令提示符运行此命令:

    netsh http add urlacl url=http://*:5555/ user="NT AUTHORITY\INTERACTIVE"

  2. In %USERPROFILE%\Documents\IISExpress\config\applicationhost.config,将站点的本地主机绑定替换为 bindingInformation="*:5555:*"。结果应如下所示:

    <site name="..." id="...">
        <!-- application settings omitted for brevity -->
        <bindings>
            <binding protocol="http" bindingInformation="*:5555:*" />
        </bindings>
    </site>

Grant yourself permission to bind to network adapters other than localhost, and configure IIS express to bind to all adapters.

IIS Express will then accept connections from the Android emulator via 10.0.2.2. If you add a rule to the firewall, you can also expose IIS Express to your network, which decreases security but is useful for testing physical devices.

Step details: (they assume a port number of 5555 - use your actual port instead)

  1. Run this from a command prompt as Administrator:

    netsh http add urlacl url=http://*:5555/ user="NT AUTHORITY\INTERACTIVE"

  2. In %USERPROFILE%\Documents\IISExpress\config\applicationhost.config, replace your site's localhost binding with bindingInformation="*:5555:*". The result should look like this:

    <site name="..." id="...">
        <!-- application settings omitted for brevity -->
        <bindings>
            <binding protocol="http" bindingInformation="*:5555:*" />
        </bindings>
    </site>
做个少女永远怀春 2024-11-20 05:55:38

将以下行添加到 II 配置文件中(例如 c:\Users[YourName]\Documents\IISExpress\config\applicationhost.config )如果需要,请更改端口 8085..

<binding protocol="http" bindingInformation="*:8085:127.0.0.1" />

这样您的配置文件最终会出现类似这样的内容,

<bindings>
<binding protocol="http" bindingInformation="*:4396:localhost" />     // the existing one
<binding protocol="http" bindingInformation="*:8085:127.0.0.1" />     // new line
</bindings>

现在您可以通过调用端口 8085 从远程调用您的 Web 服务

ex from android emu.
new HttpPost("http://10.0.2.2:8085");

Add following line to IIs config file (ex c:\Users[YourName]\Documents\IISExpress\config\applicationhost.config ) Change the port 8085 if required..

<binding protocol="http" bindingInformation="*:8085:127.0.0.1" />

so your config file will end-up with something like this

<bindings>
<binding protocol="http" bindingInformation="*:4396:localhost" />     // the existing one
<binding protocol="http" bindingInformation="*:8085:127.0.0.1" />     // new line
</bindings>

now you can call your web service from remote by calling to port 8085

ex from android emu.
new HttpPost("http://10.0.2.2:8085");
只想待在家 2024-11-20 05:55:38

默认情况下,IIS Express 仅接受来自本地主机的连接。要启用来自远程设备的连接(模拟器也算在内),请使用 此处

简而言之:

netsh http add urlacl url=http://[machinename]:[port]/ user=everyone
netsh http delete urlacl url=http://[machinename]:[port]/

[machinename][port] 替换为您的计算机名称(或非本地 IP)和 IIS Express 运行的端口。

另请参阅此问题和此一个

By default, IIS Express only accepts connections from localhost. To enable connections from remote devices (and the emulator counts as such), use the instructions from here.

In short:

netsh http add urlacl url=http://[machinename]:[port]/ user=everyone
netsh http delete urlacl url=http://[machinename]:[port]/

Replace [machinename] and [port] with your computer name (or non-local IP) and port IIS Express runs on.

Also, see this question and this one.

追我者格杀勿论 2024-11-20 05:55:38

这是我的解决方案:
我正在使用 Visual Studio Express 2013 for Web,并且我的 RESTful Web 服务在 IIS Express 上运行。
当我尝试在同一台计算机中使用 Android 模拟器访问我的 Web 服务时,它给了我这个无效主机名错误。正如上面的答案所建议的,我确实向我的 applicationhost.config 文件添加了新的绑定,但它仍然不起作用。最后,我通过“以管理员身份”运行 Visual Studio 解决了这个问题。

Here is my solution:
I am using Visual Studio Express 2013 for Web and my RESTful web service is running on IIS express.
When I tried to access my web service using an Android emulator in the same machine it gave me this invalid hostname error. As suggested by above answers I did add new bindings to my applicationhost.config file but still it didn't work. At last, I was able to fix this issue by running Visual Studio "as administrator".

风轻花落早 2024-11-20 05:55:38

您需要为您的电脑名称添加新的绑定,或将绑定更改为 *::*::,然后允许该端口使用具有高级安全性的 Windows 防火墙

要查看的文件是第 167 行左右的 <解决方案文件夹>\.vs\<项目名称>\config\applicationhost.config

You need to add a new binding for your PC name or change a binding to *:<port>:* or :<port>: and then allow that port using Windows Firewall with Advanced Security.

File to look into is <solution folder>\.vs\<project name>\config\applicationhost.config around line 167

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文