我有一个网站(MVC3),用于开发托管在 IIS Express 中。(我遇到了 Cassini Devserver 的错误,不得不升级......)现在,我想知道,是否可以让我本地网络上的其他机器(路由器后面)看到该站点托管在我的机器上?(例如,如果我将http://my.local.ip:port写入与我在同一个 LAN 上的浏览器中,页面会加载吗?)
6 回答
默认情况下,IIS Express 仅服务于 localhost 请求。要为外部请求提供服务,请编辑applicationhost.config
文件(位于 中%userprofile%\documents\iisexpress\config\
)并更改localhost
为'*'
或您的机器名称。(请记住,对于非本地主机绑定,您必须以管理员身份运行或将 URL acl 设置为管理员,然后以非管理员身份运行 iisexpress)
或者,您可以使用类似AnalogX 的 PortMapper 之类的东西充当小型环回代理,将私有 localhost 绑定端口隧道连接到公共开放端口。
例如,
- IISExpress本地绑定到localhost:8080
- PortMapper端口9090配置为将流量中继到localhost:8080
实际上,端口9090上的任何连接(由PortMapper打开)都将通过隧道连接到localhost:8080;从而绕过所有有时会很痛苦的 netsh 废话。
下面是我的配置:
使用这种代理方法的好处是它不会在本地开发盒上永久公开打开的IISExpress端口。
很少,有时我想公开开放端口进行会议;但大多数时候,端口应该关闭并且只能由 localhost 访问。每次修改路由器上的防火墙规则是一件痛苦的事。以下是我的设置方式:
- 我的路由器防火墙将9090端口转发到PortMapper
- 仅当PortMapper正在运行时,PortMapper才会继续将流量代理到IISExpress(在8080上侦听)。
笔记
确保关闭所有PortMapper窗口以使任何更改生效。
笔记2
正如其他人所描述的,您可能需要为您的应用程序调整IISExpress绑定
My Documents\IISExpress\applicationhost.config
project\.vs\config\applicationhost.config
类似于:
<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>
我认为要成功,需要三个步骤:
1)添加一个dns条目或hosts条目,以便其他机器可以查找开发机器的IP地址
2)像这样在 %userprofile/documents/IISExpress/Config 中添加到 applicationhost.config 的绑定
<site name="MobileDashboard(2)" id="7">
<bindings>
...
<binding protocol="http" bindingInformation="*:yourport#:yourmachinendnsname" />
</bindings>
</site>
3) 运行此处找到的命令以允许传入请求:
netsh http add urlacl url=http://yourmachinendnsname:yourport#/ user=everyone
这个线程的答案很好,它只是忽略了防火墙例外。
netsh advfirewall firewall add rule name="IIS Express (non-SSL)" action=allow protocol=TCP dir=in localport=8000
netsh advfirewall firewall add rule name="IIS Express (SSL)" action=allow protocol=TCP dir=in localport=44300
来自评论@http ://blogs.iis.net/vaidyg/archive/2010/07/29/serving-external-traffic-with-webmatrix-beta.aspx
来自http://blogs.microsoft.co.il/blogs/shair/archive/2008/12/15/how-to-use-fiddler-on-localhost.aspx的 Fiddler 中的自定义规则技巧最终对我有用。
是的,您可以使用 iis express 配置尽可能多的站点以供本地局域网使用,这里是从局域网 IIS Express 访问本地站点的链接,它解释了如何实现这一点。