错误请求 - Visual Studio 2013 中的 Asp.net WebAPI 项目的主机名无效 [英] Bad Request - Invalid Hostname with Asp.net WebAPI project in Visual Studio 2013

查看:29
本文介绍了错误请求 - Visual Studio 2013 中的 Asp.net WebAPI 项目的主机名无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Visual Studio Pro 2013 中运行一个非常基本的 webAPI 项目.它在我机器上的本地主机上运行良好.然后我尝试从另一台机器转到浏览器并转到 :57571 类似于我如何通过将服务器 ipaddress 后跟端口号指向 rails 应用程序.然后我得到错误请求 - 主机名无效 HTTP 错误 400.请求主机名无效.

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.

我还通过在 azure 中放置两台 Windows 机器来复制这一点.一个运行 Visual Studio pro 2013.我运行相同的应用程序,它在本地运行良好.然后,如果我尝试从另一个 VM(在同一虚拟网络上,我也可以 ping 服务器 vm)指向它,我仍然收到 错误请求 - 无效的主机名 HTTP 错误 400.请求主机名无效.

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.

请注意,我不关心自定义域,我只想能够使用 IP 地址从另一台机器运行此应用程序.这可能吗?(如果有关于我做错了什么的任何想法?)这是我尝试过的对我不起作用这也不起作用

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

如何判断 Visual Studio 是否以管理员身份运行?

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

(我使用的是运行 Visual Studio 的 Windows Server 2012 R2.我关闭了两台机器上的防火墙)

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

推荐答案

这是我如何让它工作的.

Here is how I got it to work.

Visual Studio 2013

将以下行添加到 applicationhost.config 使其工作

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

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

这不起作用

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

Vs2015 更新以及此更改的确切位置application.config 概述如下.

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

VS 2015 的文件路径如下.

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

C:Users\{您的用户名}DocumentsVisual Studio 2015Projects\{ThisSolutionName}\.vsconfigapplicationhost.config 正如丹尼尔提到的那样.

C:Users\{YourUsername}DocumentsVisual Studio 2015Projects\{ThisSolutionName}\.vsconfigapplicationhost.config as Daniel mentioned.

我要把它放在我的 application.config 的什么位置?

以下是 XML 文件中的父部分,您可以在其中找到绑定.

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>

这是一个新项目的大约第 161 行,它没有更改 applicationhost.config 中的任何内容.

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

我没有意识到的是,我认为客户端的 IP 地址是什么,实际上并非如此.原因是我在 Azure 中有一个 VNet 到 VNet 连接,连接两个 IP 地址的网关在我的应用程序运行的网络上重新分配客户端 IP 地址.因此,我不得不查找它映射到的新 IP 地址,以便不使用 *:port:* 策略

What I didn't realise is what I thought the clients IP address was, actually wasn't 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

这篇关于错误请求 - Visual Studio 2013 中的 Asp.net WebAPI 项目的主机名无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆