【问题标题】:allow prefix before localhost domain name in IIS express在 IIS express 中允许在 localhost 域名前添加前缀
【发布时间】:2015-10-15 04:56:41
【问题描述】:

我正在构建一个 MVC Web 应用程序,它应该响应 a.sub.example.com、b.sub.example.com、c.sub.example.com 等域。我可以弄清楚如何取出 a、b、c 等前缀并相应地创建正确的路由,但我正在努力让 IIS 网络服务器将请求实际转发到同一个网络应用程序。

我按照this 指南让 IIS express 监听另一个地址,在本例中为 sub.example.com,它工作正常。但是,我无法弄清楚如何让它监听该子域的所有子域。当我将浏览器定向到 a.sub.example.com 时,出现错误:

HTTP Error 400. The request hostname is invalid.

我在 hosts 文件中添加了 sub.example.com 和 a.sub.example.com 作为 127.0.0.1 的别名。

我的 applicationhost.config 文件的“站点”条目如下所示:

<site name="MyProject.Web" id="7">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="..." />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:8888:sub.example.com" />
    </bindings>
    <applicationDefaults applicationPool="Clr2IntegratedAppPool" />
</site>

当我将 'bindingInformation 属性替换为

"*:8888:*.sub.example.com" 

正如前面提到的指南所建议的,当我希望 IIS Express 监听多个域时,IIS Express 根本无法启动。

我在这里遗漏了什么明显的东西吗?

【问题讨论】:

  • 查看此链接以获取有关使用 MVC 的子域的信息。 csharptechies.blogspot.com/2013/11/…
  • 您建议的博文主要是关于如何正确设置mvc路由以使子域链接到区域。据我所知,其中没有关于如何让 IIS express 支持子域的内容。

标签: visual-studio-2013 asp.net-mvc-5 iis-express


【解决方案1】:

我知道的方法是设置 IIS applicationhost.config(完整路径:%UserProfile%\Documents\IISExpress\config\applicationhost.config)并找到对端口号的引用。

<site name="WebSite1" id="1">
      <application path="/">
            <virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%WebSite1" />
      </application>
      <bindings>
            <binding protocol="http" bindingInformation=":49483:localhost" />
      </bindings>
</site>

我通常添加 &lt;binding protocol="http" bindingInformation=":49483:" /&gt; 以接受该端口上的所有主机(注意空字符串,而不是通配符 *)。

您必须在 hosts 文件中将此主机设置为指向 127.0.0.1。或者,使用您拥有的域并将 .sub.mydomain 指向 127.0.0.1。 Hosts 文件不支持通配符 (),但 DNS 支持!这意味着我可以轻松设置 myproject.sub.mydomain 和 myproject.sub.mydomain 而无需向我的主机文件添加新行(只要我有互联网连接)!

希望对你有帮助

【讨论】:

  • 将 bindingInformation 更改为 ":8888:" 就可以了,但我仍然需要将每个子域分别放在我的 hosts 文件中。当我将 127.0.0.1 .sub.example.com 放入主机文件时,我的浏览器中出现“ERR_NAME_NOT_RESOLVED”错误。
  • 尽量不要在你的主机文件中使用域名。只是子名称,如果你想要 test.localhost 只需使用 test 没有域,
猜你喜欢
  • 1970-01-01
  • 2014-09-29
  • 2015-12-29
  • 2013-08-08
  • 2013-06-24
  • 1970-01-01
  • 1970-01-01
  • 2013-01-30
  • 1970-01-01
相关资源
最近更新 更多