.net 使用 IIS Express 托管网站(临时)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5235826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:21:21  来源:igfitidea点击:

Using IIS Express to host a website (temporarily)

.netiisiis-express

提问by TDaver

I have a website (MVC3), which for developement is hosted in IIS Express. (I've run into a bug of Cassini Devserver and had to upgrade...) Now, I'm wondering, is it possible to let other machines on my local net (behind router) see the site as hosted on my machine? (e.g. If I write http://my.local.ip:portinto a browser on the same LAN as I am will the page load?)

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

回答by vikomall

By default IIS Express serves only localhost requests. To serve external requests edit applicationhost.configfile (located in %userprofile%\documents\iisexpress\config\) and change localhostto '*'or your machine name. (remember for non-localhost binding you must be running as administrator or set URL acl as an administrator and then run iisexpress as non-administrator)

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

回答by Brian Chavez

Alternatively, you can use something like AnalogX's PortMapperto act as a small loopback proxy to tunnelprivately localhost bound ports to publicly open ports.

或者,您可以使用类似AnalogX 的 PortMapper 之东西来充当小型环回代理,以将私有本地主机绑定端口隧道连接到公共开放端口。

For example,

例如,

  • IISExpressis locally bound to localhost:8080
  • PortMapperport 9090is configured to relay traffic to localhost:8080
  • IISExpress本地绑定到localhost:8080
  • PortMapper端口9090配置为将流量中继到localhost:8080

Effectively, any connection on port 9090(opened by PortMapper) will be tunneled to localhost:8080; thereby bypassing all the netsh nonsense which can be a pain sometimes.

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

Below is my configuration:

下面是我的配置:

PortMapper configuration

端口映射器配置

The benefit of using this proxying method is that it does not permanently expose an open IISExpressport on the local dev box.

使用这种代理方法的好处是它不会在本地开发框上永久公开一个开放的IISExpress端口。

Rarely, there are times when I want to open the port publicly for meetings; but most of the time, the port should closed and only be accessible by localhost. Modifying firewall rules on the router every time is a pain. Here's how I have things setup:

很少,有时我想公开开放端口以进行会议;但大多数时候,端口应该关闭并且只能由本地主机访问。每次修改路由器上的防火墙规则都很痛苦。这是我如何设置:

  • My router firewall forwards 9090port to PortMapper
  • PortMapperonly continues proxying the traffic to IISExpress(listening on 8080) only if PortMapperis running.
  • 我的路由器防火墙将9090端口转发到PortMapper
  • 仅当PortMapper正在运行时,PortMapper才会继续将流量代理到IISExpress(在8080 上侦听)。

Note

笔记

Make sure to close out all the PortMapperwindows for any changes to take effect.

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

Note 2

笔记2

As others have described, you might need to adjust the IISExpressbindings for your application in

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

 My Documents\IISExpress\applicationhost.config
 project\.vs\config\applicationhost.config

to something like:

类似于:

<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>

回答by kevinc

I believe there are three steps to making this succesful:

我认为要做到这一点,需要三个步骤:

1) Add a dns entry or hosts entries so other machines can lookup the dev machine's ip address

1) 添加 dns 条目或 hosts 条目,以便其他机器可以查找开发机器的 ip 地址

2) Add a binding to applicationhost.config in %userprofile/documents/IISExpress/Config like so

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

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

3) Run the command found hereto allow incoming requests:

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

netsh http add urlacl url=http://yourmachinendnsname:yourport#/ user=everyone

回答by fyberoptik

The answer in this thread is great, it just leaves out the firewall exceptions.

这个线程中的答案很好,它只是忽略了防火墙例外。

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

Sourced from comments @ http://blogs.iis.net/vaidyg/archive/2010/07/29/serving-external-traffic-with-webmatrix-beta.aspx

来自评论@ http://blogs.iis.net/vaidyg/archive/2010/07/29/serving-external-traffic-with-webmatrix-beta.aspx

回答by gius

回答by Nasir Mahmood

yes you can configure as many sites using iis express for local lan use here is link Accessing local sites from Lan IIS Expresswhich explain how to achieve this.

是的,您可以使用 iis express 配置尽可能多的站点以供本地 lan 使用,这里是从 Lan IIS Express 访问本地站点的链接,它解释了如何实现这一点。