517

如何在 IIS Express 中启用远程请求?斯科特格思里写道这是可能的,但他没有说如何。

4

26 回答 26

417

现在 IIS 团队网站上有一篇博文,解释了如何在 IIS Express 上启用远程连接。以下是该帖子的相关部分总结:

在 Vista 和 Win7 上,从管理提示符运行以下命令:

netsh http add urlacl url=http://vaidesg:8080/ user=everyone

对于 XP,首先安装 Windows XP Service Pack 2 支持工具。然后从管理提示符运行以下命令:

httpcfg set urlacl /u http://vaidesg1:8080/ /a D:(A;;GX;;;WD)

于 2010-07-29T15:55:30.397 回答
375

您可能需要进行三项更改。

  1. 告诉 IIS Express 本身绑定到所有 IP 地址和主机名。在你的.config文件中。通常:
    • 与 2015 年相比: $(solutionDir)\.vs\config\applicationhost.config
    • < 与 2015 年相比:%userprofile%\My Documents\IISExpress\config\applicationhost.config

找到您网站的绑定元素,然后添加

    <binding protocol="http" bindingInformation="*:8080:*" />
  1. 设置名为“http.sys”的 Windows 位。以管理员身份运行以下命令:
    netsh http add urlacl url=http://*:8080/ user=everyone

everyonewindows组在哪里。对带有空格的组使用双引号,例如“Tout le monde”。

  1. 允许 IIS Express 通过 Windows 防火墙。

    开始 / 具有高级安全性的 Windows 防火墙 / 入站规则 / 新规则...

    程序%ProgramFiles%\IIS Express\iisexpress.exe
    或端口 8080 TCP

现在,当您开始时,iisexpress.exe您应该会看到一条消息,例如

成功为站点“hello world”应用程序“/”注册 URL“http://*:8080/”

于 2013-04-04T11:19:56.267 回答
153

在我找到iisexpress-proxy之前,没有什么对我有用。

以管理员身份打开命令提示符,然后运行

npm install -g iisexpress-proxy

然后

iisexpress-proxy 51123 to 81

假设您的 Visual Studio 项目在 localhost:51123 上打开,并且您想要访问外部 IP 地址 xxxx:81

编辑:我目前正在使用ngrok

于 2015-11-10T05:20:25.767 回答
142

我记得几个月前在尝试这个工作流程时遇到了同样的问题。

这就是为什么我专门为这种场景编写了一个简单的代理实用程序:https ://github.com/icflorescu/iisexpress-proxy 。

使用IIS Express 代理,一切都变得非常简单——无需“netsh http add urlacl url=vaidesg:8080/user=everyone”或弄乱您的“applicationhost.config”。

只需在命令提示符下发出此命令:

iisexpress-proxy 8080 to 3000

…然后您可以将远程设备指向http://vaidesg:3000

大多数时候更简单更好。

于 2015-04-30T15:23:59.607 回答
41

如果您使用的是 Visual Studio,请按照以下步骤通过 IP 地址访问 IIS-Express:

  1. 获取您的主机 IP 地址:ipconfig在 Windows 命令行中
  2. $(SolutionDir)\.vs\config\applicationHost.config
    
  3. 寻找

    <site name="WebApplication3" id="2">
       <application path="/" applicationPool="Clr4IntegratedAppPool">
          <virtualDirectory path="/" physicalPath="C:\Users\user.name\Source\Repos\protoype-one\WebApplication3" />
       </application>
       <bindings>
         <binding protocol="http" bindingInformation="*:62549:localhost" />
       </bindings>
    </site>
    
  4. 添加: <binding protocol="http" bindingInformation="*:62549:192.168.178.108"/>
    使用您的 IP 地址

  5. 以管理员权限运行 Visual Studio,一切正常
  6. 如果您尝试从远程连接,可能会寻找一些防火墙问题
于 2017-03-31T07:33:15.787 回答
37

作为旁注:

netsh http add urlacl url=http://vaidesg:8080/ user=everyone

这仅适用于英文版的 Windows。如果您使用的是本地化版本,则必须将“everyone”替换为其他内容,例如:

  • 使用荷兰语版本时的“Iedereen”
  • 使用德语版本时的“Jeder”
  • 使用匈牙利语版本时的“Mindenki”

否则会报错(创建 SDDL 失败,错误:1332)

于 2013-05-12T14:01:06.037 回答
32

一个很好的资源是Scott Hanselman的 IISExpress 在开发时使用 SSL 更容易。

您所追求的是让 IIS Express 通过端口 80 在外部提供服务的部分

于 2011-05-25T04:12:57.923 回答
25

我通过在 Visual Studio Professional 2015 中安装“Conveyor by Keyoti”解决了这个问题。Conveyor 使用启用外部请求的端口 (45455) 生成远程地址(您的 IP)。例子:

在此处输入图像描述

Conveyor 允许您从网络上的外部平板电脑和手机或 Android 模拟器(不带http://10.0.2.2:<hostport>)测试 Web 应用程序

步骤在以下链接中:

https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti

于 2017-06-19T20:05:59.467 回答
11

对我有帮助的是右键单击“IISExpress”图标“显示所有应用程序”。然后选择网站,我看到它使用了哪个 aplicationhost.config,并且更正完美。

IISExpress 配置

于 2016-11-18T08:31:53.480 回答
11

这是我使用 Visual Studio 2015 为 Windows 10 所做的,以启用远程访问,包括 http 和 https:

第一步是将您的应用程序绑定到您的内部 IP 地址。运行cmd->ipconfig以获取地址。打开文件/{project folder}/.vs/config/applicationhost.config并向下滚动,直到找到如下内容:

<site name="Project.Web" id="2">
    <application path="/">
        <virtualDirectory path="/" physicalPath="C:\Project\Project.Web" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:12345:localhost" />
    </bindings>
</site>

bindings. 如果您愿意,也可以使用 HTTPS:

<binding protocol="http" bindingInformation="*:12345:192.168.1.15" />
<binding protocol="https" bindingInformation="*:44300:192.168.1.15" />

将以下规则添加到防火墙,cmd以管理员身份打开新提示并运行以下命令:

netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=12345 profile=private remoteip=localsubnet action=allow

netsh advfirewall firewall add rule name="IISExpressWebHttps" dir=in protocol=tcp localport=44300 profile=private remoteip=localsubnet action=allow

现在启动 Visual Studio 作为Administrator. 右键单击 web 项目项目文件并选择Properties. 转到Web选项卡,然后单击Create Virtual Directory。如果 Visual Studio 没有以管理员身份运行,这可能会失败。现在一切都应该工作了。

在此处输入图像描述

于 2016-12-07T11:56:40.860 回答
10

如果您尝试过上校 Panic 的回答但在 Visual Studio 中不起作用,请尝试以下操作:

<binding />在 IIS Express 配置中添加另一个

<bindings>
    <binding protocol="http" bindingInformation="*:8080:localhost" />
    <binding protocol="http" bindingInformation="*:8080:hostname" />
</bindings>

最后,您必须以管理员身份运行 Visual Studio

于 2015-07-01T06:52:42.283 回答
10

结合这个线程中的答案,这就是我修复它的方法(Visual Studio 2019):

  1. 以管理员身份启动 Visual Studio并像往常一样运行 Web 服务。

  2. 在任务栏上找到 IIS Express 图标,右键单击它,然后单击“显示所有应用程序”。

  3. 选择您的 Web 服务并注意下面显示的配置路径。单击配置文件以将其打开以进行编辑。

  4. 在此配置文件中找到您的 Web 服务(例如搜索您的端口),然后找到如下一行: *: yourport :localhost

  5. 之后添加一个新行,如下所示:

    :你的港口*

在这种情况下,无需创建具有将来可能更改的特定 IP 地址的绑定。

我希望这可以帮助那里的人。

于 2020-09-14T13:52:53.173 回答
8

我发现的最简单和最酷的方法是使用(设置需要 2 分钟):

https://ngrok.com/

它适用于在 localhost 上运行的任何东西。只需注册,运行很少的可执行文件,您在 localhost 上运行的任何内容都会获得您可以从任何地方访问的公共 URL。

这对于向您的远程团队成员展示内容非常有用,无需摆弄 IIS 设置或防火墙。想要停止访问只需终止可执行文件。

ngrok authtoken xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

ngrok http -host-header=localhost 89230

假设 89230 是您的 IIS Express 端口

即使是免费计划,您也可以运行多个端口

于 2018-11-01T14:17:29.920 回答
5

这个问题的公认答案是让 IIS Express 与 webmatrix 一起工作的指南。我发现本指南在尝试使其与 VS 2010 一起使用时更有用。

我只是按照第 3 步和第 4 步(以管理员身份运行 IIS Express)并不得不暂时禁用我的防火墙以使其正常工作。

于 2011-05-16T00:19:20.820 回答
5

您可以尝试设置端口转发,而不是尝试修改 IIS Express 配置、添加新的 HTTP.sys 规则或以管理员身份运行 Visual Studio。

基本上,您需要将IP:PORT您的网站运行在您机器上的其他一些空闲端口上,但在外部网络适配器上,而不是本地主机上。

问题是 IIS Express(至少在 Windows 10 上)绑定到[::1]:port意味着它侦听 IPv6 端口。您需要考虑到这一点。

这是我完成这项工作的方式 - http://programmingflow.com/2017/02/25/iis-express-on-external-ip.html

希望能帮助到你。

于 2017-03-07T09:42:13.637 回答
3

我在 Win 8.1 和外部请求中使用 IIS Express 时遇到了一些问题。

我按照以下步骤调试外部请求:

  1. 安装 IIS
  2. 将 Visual Studio 配置为使用本地 IIS(Web 项目中的页面属性)
  3. 在 IIS 中创建一个专属 AppPool 以使用我的应用程序
  4. 在我的项目中,我使用的是 Oracle 客户端,并且必须是 32 位(64 位不适用于 Visual Studio),然后我需要在应用程序池中允许 32 位
  5. 配置 Windows 防火墙以允许端口 80 中的请求(入站规则)

它正在工作!

于 2014-08-03T19:51:16.593 回答
3

访问外部请求的另一种方法是使用 IIS 而不是 IIS Express。在我的视觉工作室中,我可以轻松切换。

在此处输入图像描述

于 2020-03-03T09:57:09.560 回答
2

我启用了本地 IIS,所以我刚刚为我的调试端口创建了一个重写规则......我认为这比其他方法更好,更酷,因为一旦完成开发就更容易删除......这是重写的外观。 .

<rewrite>
    <rules>
        <rule name="ReverseProxyInboundRule1" stopProcessing="true">
            <match url="^dev/(.*)" />
            <action type="Rewrite" url="http://localhost:47039/{R:1}" />
        </rule>
    </rules>
</rewrite>

VS 还允许您直接使用本地 IIS 进行开发(然后允许远程连接),但反过来您必须始终以管理员身份运行它......我不喜欢那样。

于 2016-09-20T16:11:52.640 回答
2

如果您从 Admin 运行 Visual Studio,您可以只添加

<binding protocol="http" bindingInformation="*:8080:*" />

或者

<binding protocol="https" bindingInformation="*:8443:*" />

进入

%userprofile%\My Documents\IISExpress\config\applicationhost.config
于 2016-12-26T23:34:14.867 回答
1

我做了所有这些步骤,但没有任何帮助。而我需要的是,它只是通过 IIS Express 运行我的应用程序......

在此处输入图像描述

希望能帮助到你。

于 2019-02-18T10:58:43.020 回答
1

我通过使用反向代理方法解决了这个问题。

我安装了 wamp 服务器并使用了 apache web 服务器的简单反向代理功能。

我添加了一个新端口来监听 Apache Web 服务器(8081)。然后我将代理配置添加为该端口的虚拟主机。

<VirtualHost *:8081>
ProxyPass / http://localhost:46935/
ProxyPassReverse / http://localhost:46935/
</VirtualHost>
于 2016-11-09T08:24:06.757 回答
1

对我来说使用这个,相对简单,直接:

通过在“扩展”对话框中搜索“传送带”来下载Visual Studio 扩展。然后只需安装。

表格: https ://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti

于 2020-08-20T09:05:04.077 回答
0

我无法向本地网络中的其他用户提供 iis 请求,我所要做的(除了上述之外)就是重新启动我的 BT Hub 路由器。

于 2015-04-01T10:01:09.853 回答
0

我做了以下并且能够连接:

1) 将 IIS express 配置绑定从本地主机更改为 '*'

绑定协议="http" 绑定信息="*:8888:*"

2) 在防火墙上定义入站规则以允许协议类型的特定端口:tcp

3) 添加以下命令为您的端口添加网络配置: netsh http add urlacl url=http://*:8888/ user=everyone

于 2016-10-21T20:02:08.047 回答
0

这真是太棒了,甚至涵盖了带有漂亮域名的 HTTPS:

http://www.hanselman.com/blog/WorkingWithSSLAtDevelopmentTimeIsEasierWithIISExpress.aspx

万一上面的链接消失了,我在其他任何地方都找不到真正棒的部分:

> C:\Program Files (x86)\IIS Express>IisExpressAdminCmd.exe Usage:
> iisexpressadmincmd.exe <command> <parameters> Supported commands:
>       setupFriendlyHostnameUrl -url:<url>
>       deleteFriendlyHostnameUrl -url:<url>
>       setupUrl -url:<url>
>       deleteUrl -url:<url>
>       setupSslUrl -url:<url> -CertHash:<value>
>       setupSslUrl -url:<url> -UseSelfSigned
>       deleteSslUrl -url:<url>
> 
> Examples: 1) Configure "http.sys" and "hosts" file for friendly
> hostname "contoso": iisexpressadmincmd setupFriendlyHostnameUrl
> -url:http://contoso:80/ 2) Remove "http.sys" configuration and "hosts" file entry for the friendly  hostname "contoso": iisexpressadmincmd
> deleteFriendlyHostnameUrl -url:http://contoso:80/

以上实用程序将为您注册 SSL 证书!如果您使用 -UseSelfSigned 选项,则非常简单。

如果您想以艰难的方式做事,不明显的部分是您需要告诉 HTTP.SYS 使用什么证书,如下所示:

netsh http add sslcert ipport=0.0.0.0:443 appid={214124cd-d05b-4309-9af9-9caa44b2b74a} certhash=YOURCERTHASHHERE

Certhash 是您可以从 MMC 中的证书属性中获取的“指纹”。

于 2015-11-03T05:18:34.250 回答
-1

[项目属性对话框]

使用 VisualStudio 2017 和 NetCore API 项目进行开发:

1) 在 Cmd-Box 中: ipconfig /all 确定 IP 地址

2a) 在项目属性-> 调试选项卡中输入检索到的 IP 地址

2b) 选择一个端口并将其附加到步骤 2a 中的 IP 地址。

3) 在防火墙中添加允许规则以允许所选端口上的传入 TCP 流量(我的防火墙通过对话框触发:“阻止或向防火墙添加规则”)。在这种情况下,添加会解决问题。

上述解决方案的缺点:

1) 如果您使用动态 IP 地址,则需要重新执行上述步骤,以防分配了另一个 IP 地址。

2)您的服务器现在有一个您可能会忘记的开放端口,但这个开放端口仍然是对不受欢迎的客人的邀请。

于 2018-06-20T12:49:56.970 回答