【问题标题】:Setting localhost alias in IIS Express for Visual Studio在 IIS Express 中为 Visual Studio 设置 localhost 别名
【发布时间】:2014-03-23 05:38:19
【问题描述】:

我正在尝试在 Visual Studio 2013 的开发环境中定义 localhost 的别名。

当我使用以前版本的 Visual Studio 时,我使用 Visual Studio Development Server 进行调试,我唯一需要做的就是更改我的 hosts 文件添加以下条目:

127.0.0.1   localhost    
127.0.0.1   localhostalias

我在使用 VS2013 时遇到问题。我浏览了整个互联网,并尝试了以下方法,但我希望你们中的某个人告诉我我做错了什么。我显然已经更改了主机文件...

在 Web 项目属性 -> Web 部分中选择 IIS Express 作为默认设置的服务器中,我尝试将 http://localhost:53944 更改为 http://localhostalias:53944,但显示错误:“Unable to create the virtual directory. Cannot create the Web site 'http://localhostalias:53944'. You must specify "localhost" for the server name”。

我还尝试将位于 \IISExpress\config 中的 applicationhost.config 更改为

        <site name="<<Site name>>" id="2">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="<<Site Path>>" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:53944:*" />
            </bindings>
        </site>

当我打开项目时它被更改为

        <site name="<<Site name>>" id="2">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="<<Site Path>>" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:53944:*" />
            </bindings>
        </site>
        <site name="<<Site name>>(1)" id="3">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="<<Site Path>>" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:53944:localhost" />
            </bindings>
        </site>

有人可以帮我吗?

提前致谢,

卡米洛

【问题讨论】:

    标签: localhost visual-studio-2013 alias iis-express


    【解决方案1】:

    如果您访问此页面寻找 VS2015+ 的解决方案,您正在寻找的 applicationhost.config 文件不再位于 documents\IISExpress\config 上。

    新位置是{solutiondir}\.vs\config\applicationhost.config

    【讨论】:

      【解决方案2】:

      由于 Jack 的答案中的链接 URL 目前不起作用,并且解决方案(至少对我而言)已包含在 answer to another question 中,因此我将在此处重复答案:

      您可以设置多个绑定。因此,您可以为您希望服务的每个外部地址设置绑定,它会起作用:

      <bindings>
          <binding protocol="http" bindingInformation=":1904:" />
          <binding protocol="http" bindingInformation=":1904:machineName" />
          <binding protocol="http" bindingInformation=":1904:10.1.10.123" />
      </bindings>
      

      【讨论】:

        【解决方案3】:

        我这里也遇到了类似的错误,原来解决方法可以在:http://stonycreektechnologies.com/2011/03/15/iis-express-enable-remote-requests/

        对我来说,这只是在那里运行命令的一个例子(我将它用于端口 8080 和我的项目的端口 55968,只是为了确定)并关闭并重新打开我的项目,编辑我的 applicaitonhost.config文件,然后通过 Visual Studio gui 更改站点的设置。

        要注意的另一件事是,您可能会在 applicationhost.config 文件中获得多个端口号条目。这很糟糕,您只想要一个,因此您可以安全地剔除具有相同端口的其他条目。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-12-13
          • 2016-11-13
          • 2016-06-04
          • 2015-03-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-10-21
          相关资源
          最近更新 更多