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


当前回答

帮助我的是右键单击“IISExpress”图标,“显示所有应用程序”。然后选择网站,我看到哪个应用程序主机。它使用的配置,纠正进行得很完美。

其他回答

如果你尝试过Panic上校的答案,但在Visual Studio中不起作用,试试这个:

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

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

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

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

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

npm install -g iisexpress-proxy

then

iisexpress-proxy 51123 to 81

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

编辑:我目前正在使用ngrok

[项目属性对话框]

使用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不是以管理员身份运行,则可能会失败。现在一切都正常了。

如果你正在使用Visual Studio,那么按照以下步骤通过ip地址访问IIS-Express:

Get your host IP-Adress: ipconfig in Windows Command Line GoTo $(SolutionDir)\.vs\config\applicationHost.config Find <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> Add: <binding protocol="http" bindingInformation="*:62549:192.168.178.108"/> with your IP-Adress Run your Visual Studio with Administrator rights and everything should work See post from Andrii how to configure Firewall: here