I just finished adding C# Web API components (Web API Models & Controllers) to a localhost
copy of an existing project.
This Web API\'s GET-methods shou
This worked form me On visual Studio >= 2017, for dotnet core projects:
1- Edit applicationhost.config located inside .vs\config in your project and add bindings for 127.0.0.1 for http and https:
<sites>
...
<site name="Api" id="3"> <!-- your api project -->
...
<bindings>
<binding protocol="https" bindingInformation="*:44380:localhost" />
<binding protocol="http" bindingInformation="*:55555:localhost" />
<binding protocol="https" bindingInformation="*:44380:127.0.0.1" />
<binding protocol="http" bindingInformation="*:55555:127.0.0.1" />
</bindings>
</site>
...
</sites>
2- edit iisexpress launch settings in vs: from solution explorer under the api project tree
[your project] > properties > launchSettings.json:
"iisSettings": {
...
"iisExpress": {
**"applicationUrl": "https://127.0.0.1:44380",// make sure to use https**
"sslPort": 44380
}
},
make sure to use https in "applicationUrl": "https://127.0.0.1:44380"
I know it's a bit old post. But my solution could help someone at least a few minutes time. If you have more than one bindings on the website you are running delete it. Have have only one with IP address: All Unassigned and HostName set to Blank
It's probably not an Android nor Windows issue. If you run your localhost by Visual Studio you will not get it available via 127.0.0.1
Instead try to set IIS at your computer, then deploy from Visual Studio to IIS
Alternatively, try UltiDev products: http://ultidev.com/products/cassini/CassiniDevGuide.htm http://ultidev.com/products/UWS-Cassini-Pro/Default.aspx
Some peoples managed to use tunneling, but I never tried it and have no clue what to recommend.
Just something which listening to 127.0.0.1 and redirecting data from-to it and localhost
So typically an HTTP 400 Invalid Hostname error usually means you do not have the website set accept all hostnames and/or IP addresses. I presume because this is a C# application you are hosting this on IIS. To fix this open up IIS Manager (Win+R and enter inetmgr
), expand the server then Sites, then right-click on the the website where your application is hosted and select bindings. In this list there should be an http binding for port 54408, double-click on this. Under IP address make sure All Unassigned is selected, and under Host name make sure the field is blank. Hit OK, then Close. The setting should take effect immediately without needing to reset IIS.
If you are only testing this through Visual Studio's built in web deployment, there are similar settings to the above somewhere in VS (I'm a little rusty on it so I can't remember exactly where or how). Alternatively you can set up a web site in IIS exactly how you want it and then have VS deploy to that website instead of using its own internal server. I think there might be some debugging drawbacks to doing it this way though (once again I'm a little fuzzy on details, I'll edit them in when I remember them or figure it out).
A little background as to why these settings exist:
Sometimes a server needs to host multiple sites that are all to be accessed via port 80. So lets say we have foo.com
and bar.com
and they are too small to warrant getting a separate server for both of them. So instead they are both hosted on a sever with an IP address of 1.2.3.4
. Now when you enter the URL foo.com
into the browser and hit go, it first resolves the host name to 1.2.3.4
, and then it creates a request and part of that request is called the host header. The host header is filled with the hostname of the URL entered, in this case foo.com
. When the request is received by the server, it looks at the host header and serves back the content for foo.com
.
Now if you were to try and enter 1.2.3.4
into the browser, it would create a request with a blank host header, because none was specified. When the request is received by the server, it doesn't know what to do because there are two websites being hosted by the server and there is no host header to specify which one the browser is looking for, so instead it returns an error.
This is probably what is happening in your situation. Your website is being hosted under the localhost
hostname and any other request isn't being responded to. The settings I specified to change are basically telling the server that no matter what IP address (network interface) it comes in on, and no matter what the hostname it is looking for, as long as it is coming in on port 54408, serve this website.
Go into the folder .vs/config and open applicationhost.config and change
<bindings>
<binding protocol="http" bindingInformation="*:58670:localhost" />
</bindings>
to 127.0.0.1
<bindings>
<binding protocol="http" bindingInformation="*:58670:127.0.0.1" />
</bindings>
And change this too, to run directly using 127.0.0.1
If you are using Visual Studio's built in web server (IIS Express), localhost is mapped by default; to enable 127.0.0.1:
1) At path: %USERPROFILE%\Documents\IISExpress\config
2) Locate config file: applicationhost.config
3) - open config file in editor (I use notepad++)
4) Search for the site port, for example if the url is typically localhost:57578, search "57578" and you should find:
<binding protocol="http" bindingInformation="*:57578:localhost" />
5) Change this entry to:
<binding protocol="http" bindingInformation="*:57578:*" />
6) Save and exit, restart website.
Note: You will want to repeat this process any time you create a new virtual directory (changing the port number Project/Properties/Web/Project Url), which creates a new entry in the applicationhost.config file.