使用IIS Express托管网站(暂时)

TDa*_*ver 70 .net iis iis-express

我有一个网站(MVC3),用于开发的网站在IIS Express中托管.(我遇到了一个Cassini Devserver的bug,不得不升级...)现在,我想知道,是否有可能让我本地网上的其他机器(在路由器后面)看到我的机器上托管的网站?(例如,如果我将http://my.local.ip:port写入与我相同的局域网上的浏览器页面加载?)

vik*_*all 120

默认情况下,IIS Express仅提供localhost请求.要提供外部请求,请编辑applicationhost.config文件(位于%userprofile%\documents\iisexpress\config\)并更改localhost'*'或您的计算机名称.(请记住,对于非localhost绑定,您必须以管理员身份运行或将URL acl设置为管理员,然后以非管理员身份运行iisexpress)

  • 运行此命令"netsh http add urlacl url = http://*:44886/user = Everyone"并尝试再次启动它(按F5).这应该工作.以下链接也可以帮助http://learn.iis.net/page.aspx/1005/handling-url-binding-failures-in-iis-express/ (40认同)
  • fyi,你必须重启服务才能生效,否则你会收到503错误.svc重启后,对我来说非常适合. (3认同)
  • @KevinWon 我应该重新启动的服务的名称是什么? (2认同)

Bri*_*vez 12

或者,您可以使用AnalogX的PortMapper之东西作为小型环回代理,将私有的localhost绑定端口隧道传输到公共端口.

例如,

  • IISExpress本地绑定到localhost:8080
  • PortMapper端口9090配置为将流量中继到localhost:8080

实际上,端口9090上的任何连接(由PortMapper打开)都将通过隧道连接到localhost:8080 ; 从而绕过了所有的netsh废话,这有时可能是一种痛苦.

以下是我的配置:

PortMapper配置

使用此代理方法的好处是它不会永久公开本地开发框上的打开IISExpress端口.

很少有时候我想公开开放这个港口参加会议; 但大多数情况下,端口应该关闭,只能由localhost访问.每次修改路由器上的防火墙规则都很痛苦.以下是我设置的方法:

  • 我的路由器防火墙将9090端口转发到PortMapper
  • 仅当PortMapper正在运行时,PortMapper 才会继续将流量代理到IISExpress(仅在8080上侦听).

注意

确保关闭所有PortMapper窗口以使任何更改生效.

笔记2

正如其他人所描述的那样,您可能需要调整应用程序的IISExpress绑定

 My Documents\IISExpress\applicationhost.config
 project\.vs\config\applicationhost.config
Run Code Online (Sandbox Code Playgroud)

类似于:

<bindings>
  <!-- bindingInformaiton format:
          IPToBindTo:Port:DNSHostName -->

  <!--OLD:
  <binding protocol="http" bindingInformation="*:8080:localhost"/>-->

  <!--Change '*' to 127.0.0.1 and remove 'localhost' right of the port number
      to avoid invalid DNS hostname errors -->
  <binding protocol="http" bindingInformation="127.0.0.1:8080:" />

</bindings>
Run Code Online (Sandbox Code Playgroud)


kev*_*inc 6

我相信有三个步骤可以取得这样的成功:

1)添加一个dns条目或主机条目,以便其他机器可以查找开发机器的IP地址

2)在%userprofile/documents/IISExpress/Config中添加绑定到applicationhost.config,就像这样

<site name="MobileDashboard(2)" id="7">
                <bindings>
                    ...
                    <binding protocol="http" bindingInformation="*:yourport#:yourmachinendnsname" />
                </bindings>
            </site>
Run Code Online (Sandbox Code Playgroud)

3)运行此处的命令以允许传入请求:

netsh http add urlacl url=http://yourmachinendnsname:yourport#/ user=everyone
Run Code Online (Sandbox Code Playgroud)