如何在IIS Express中启用远程请求?Scott Guthrie写道,这是可能的,但他没有说明如何实现。


当前回答

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

https://ngrok.com/

它将与本地主机上运行的任何东西一起工作。只要注册,运行小可执行程序,不管你在localhost上运行什么,你都可以从任何地方访问公共URL。

这对于向远程团队成员显示内容很有好处,无需摆弄IIS设置或防火墙。要停止访问只需终止可执行文件。

ngrok authtoken xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

ngrok http -host-header=localhost 89230

假设89230是您的IIS Express端口

您也可以运行多个端口,甚至在免费计划

其他回答

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

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

使用IIS Express Proxy,一切都变得非常简单——不需要“netsh http add urlacl url=vaidesg:8080/ user=everyone”,也不需要弄乱你的“applicationhost.config”。

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

Iisexpress-proxy 8080 ~ 3000

然后你可以把你的远程设备指向http://vaidesg:3000。

大多数时候越简单越好。

结合这个帖子中的答案,这是我如何修复它(Visual Studio 2019):

以管理员身份启动Visual Studio,并像往常一样运行Web服务。 在任务栏上找到IIS Express图标,右键单击它,然后单击“显示所有应用程序”。 选择您的Web服务并注意下面显示的配置路径。单击配置文件以打开它进行编辑。 在这个配置文件中找到您的web服务(例如搜索您的端口),然后找到如下一行: *: yourport: localhost 在这之后添加新的一行,像这样: : yourport: *

在这种情况下,不需要使用将来可能会改变的特定ip地址创建绑定。

我希望这能帮助到一些人。

这是非常棒的,甚至包括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中的证书属性中获得的“Thumbprint”。

[项目属性对话框]

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

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

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

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

3)在防火墙中添加allow规则,允许从所选端口进入tcp流量 (我的防火墙被一个对话框触发:“阻止或添加规则到防火墙”)。在这种情况下,加法就可以了。

上述方案的缺点:

1)如果你使用动态ip地址,你需要重做上述步骤,以防另一个ip地址已被分配。

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

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

第一步是将应用程序绑定到内部IP地址。执行cmd -> ipconfig命令获取地址。打开文件/{项目文件夹}/.vs/config/applicationhost。配置并向下滚动,直到你找到像这样的东西:

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

将以下规则添加到您的防火墙,以admin身份打开一个新的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。右键单击web项目项目文件并选择属性。进入“Web”页签,单击“创建虚拟目录”。如果Visual Studio不是以管理员身份运行,则可能会失败。现在一切都正常了。