Frank Visaggio Frank Visaggio - 1 month ago 21
ASP.NET (C#) Question

Bad Request - Invalid Hostname with Asp.net WebAPI project in Visual Studio 2013

I am running a very basic webAPI project in Visual Studio Pro 2013. It runs fine on localhost on my machine. I then try and go to a browser from a different machine and goto :57571 similiar to how i could point to rails apps by putting the servers ipaddress followed by the port number. I then get
Bad Request - Invalid Hostname HTTP Error 400. The request hostname is invalid.

I also replicated this by putting two windows machines in azure. One running visual studio pro 2013. I run the same application and it works fine locally. Then if i try and point at it from another VM (on the same virtual network, i can also ping the server vm) I still get Bad Request - Invalid Hostname HTTP Error 400. The request hostname is invalid.

Mind you I dont care about a custom domian I just want to be able to run this app from another machine using the IP address. Is this possible? (if so any ideas on what i am doing wrong?)
Here is what i tried
Didnt work for me
This also didnt make it work

How can i tell visual studio is running as an admin?

(I am using windows Server 2012 R2 where visual studio is running. I turned off the firewall on both machines)

Answer

Here is how I got it to work.

goto C:\users\yourusername\Documents\IISExpress\config\applicationhost.config in Visual Studio 2013

Add the following line to applicationhost.config made it to work

<binding protocol="http" bindingInformation="*:53676:*" />

where this didnt work

<binding protocol="http" bindingInformation="<clientsIPaddress>:53676:*" />

Vs2015 Update and the exact location for this change the application.config are outlined below.

The path to the file is the following for VS 2015.

C:\Users\\{YourUsername}\Documents\Visual Studio 2015\Projects\\{ThisSolutionName}\\.vs\config\applicationhost.config as Daniel mentioned.

Where do i put this in my application.config?

Below are the parent sections in the xml file where you would find the bindings.

 <system.applicationHost>
           <sites>
              <site name="WebSite1" id="1" serverAutoStart="true">
                 <bindings>
                      binding protocol="http" bindingInformation=":8080:localhost" />
               </bindings>
           </site>
      </sites>
 </system.applicationHost>

This was roughly line 161 for a new project that didnt change anything in the applicationhost.config.

What I didnt realize is what I thought the clients IP address was, actually wasnt true. The reason being is that I had a VNet to VNet connection in Azure and the gateway that is connecting the two IP addresses reassigns the clients IP address on the network in which my application was running. I thus had to look up the new IP address it was mapped to in order to not use the :port: strategy

Comments