Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS Express access from Android emulator

I know similar questions have been asked many times, but I still can't get it working correctly. I'd like to be able to access IIS Express on my host machine from my Visual Studio Android emulator. I have the following bindings in my .vs\config\applicationHost.config file for my website:

<binding protocol="http" bindingInformation="*:7265:MyComp" />
<binding protocol="https" bindingInformation="*:44300:MyComp" />
<binding protocol="http" bindingInformation="*:7265:10.0.2.2" />
<binding protocol="https" bindingInformation="*:44300:10.0.2.2" />
<binding protocol="http" bindingInformation="*:7265:localhost" />
<binding protocol="https" bindingInformation="*:44300:localhost" />

When I run the website on my host, in the list of running applications, I see the bindings for MyComp and localhost listed, but not the ones for 10.0.2.2. On my host I can connect using MyComp or localhost without issue.

In the emulator, I can use http://10.0.2.2 to connect to IIS 7.5 (not express) on my host computer with no issue. In my emulator what I can't do is connect to http://10.0.2.2:7265 or https://10.0.2.2:44300 which is a site being run in IIS Express. I get an HTTP 400 error "The request hostname is invalid.". I'm sure this is because I don't have the IIS bindings set up correctly, but nothing I try works. Any ideas?

Thanks!

like image 723
NorthFork Avatar asked Apr 25 '17 23:04

NorthFork


2 Answers

In your .NET project Go to project settings | Debug and replace "localhost" to your loopback adapter "127.0.0.1" in your "app url" string.

Worked for me. app url setting in .NET project/debug settings

like image 77
user10760866 Avatar answered Sep 22 '22 07:09

user10760866


You missed a few basic facts. 10.0.2.2 on Android emulator is translated to 127.0.0.1 on the host. Thus, change your bindings to

<binding protocol="http" bindingInformation="*:7265:127.0.0.1" />
<binding protocol="https" bindingInformation="*:44300:127.0.0.1" />

You can also remove host headers from bindings by following this blog post,

https://blog.lextudio.com/how-to-let-android-emulator-access-iis-express-f6530a02b1d3

like image 29
Lex Li Avatar answered Sep 22 '22 07:09

Lex Li