很多时候我们本地的 app 需要外部访问,方便测试和调试,那么在 IIS Express 怎么添加呢?
1. 修改 IIS Express 配置文件
首先我们找到 IIS Express 的配置文件。
# 如果是全局的 IIS Express 配置,在:
C:\Users\tommmm\Documents\IISExpress\config\applicationhost.config
# 如果是项目中的,比如在 VS 中直接 debug 的 IIS Express:
..\项目根目录\.vs\PsyLocYy3\config\applicationhost.config
然后,找到 sites 这个标签,在 binding 中加入自己电脑在局域网中的 IP 地址:
<sites>
...
<site name="WebApp" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\TomsProject\WebApp" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:62597:localhost" />
<binding protocol="http" bindingInformation="*:62597:192.168.0.202" />
</bindings>
</site>
...
</sites>
2. 添加本地的 URL 访问权限
打开 CMD 或者 Powershell,用管理员身份运行,然后输入命令:
# Windows XP
httpcfg set urlacl /u http://计算机名或IP地址:62597/ /a D:(A;;GX;;;WD)
# Windows 7或更高,以管理员身份的运行cmd
netsh http add urlacl url=http://计算机名或IP地址:62597/ user=everyone
3. 修改防火墙
打开防火墙的高级设置 --> 入站规则 --> 点击右侧的新建规则
这样就可以把端口添加进去了。
我们这个例子中的端口号就是前面用到的 62597,用这个来创建规则,就可以啦。