Visual Studio 2015: IIS Express 中的自定义域名 - 主机名无效。

3
我将我的ASP.NET MVC项目升级到使用Visual Studio,然后出现了令人讨厌的“Bad Request - Invalid Hostname”错误。这个问题在以前的Visual Studio版本中已经有记录(例如在IIS Express中使用自定义域名),但我似乎找不到Visual Studio 2015的解决方案。
我使用许多自定义域名(例如http://foo.testsite.local:1299)来运行我的站点。我以管理员身份运行Visual Studio,并且我的应用程序host.config中的绑定看起来像这样:
        <bindings>
          <binding protocol="http" bindingInformation="*:1299:" />
          <binding protocol="https" bindingInformation="*:44300:" />
        </bindings>

这在Visual Studio 2013中完美运行,但是由于某些原因,在Visual Studio 2015中运行我的ASP.NET MVC应用程序会返回以下结果:
HTTP/1.1 400 Bad Request

Bad Request - Invalid Hostname

有什么解决方法吗?我需要在绑定中使用通配符,而不是硬编码的URL,因为我的应用程序支持多个域名(包括自定义子域名)。

我应该注意到这些设置与http://localhost:1299一起工作。

2个回答

7

默认情况下,VS 2015解决方案不再使用位于用户文件夹中的applicationhost.config文件。相反,它们会在解决方案下的.vs\config文件夹中动态创建一个文件。如果要使用位于用户文件夹中的全局文件,请在项目文件中设置以下属性。这是每个项目的设置。

<UseGlobalApplicationHostFile>
    true
<UseGlobalApplicationHostFile>

@Bill 抱歉,格式化操作导致 XML 代码被移除了。正确的代码应该是 <UseGlobalApplicationUserFile>true</UseGlobalApplicationUserFile> - Bill

2
  1. 前往路径 C:\Users\(用户名)\Documents\Visual Studio 2015\Projects\{你的项目文件夹}\.vs\config。
  2. 编辑文件 applicationhost.config 如下: 将 binding protocol="http" bindingInformation=":1743:localhost" 改为 binding protocol="http" bindingInformation=":1743:*"
  3. 以管理员身份打开 cmd 并输入: netsh http add urlacl url=http://*:1743/ user=everyone

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接