在vs开发时,直接调试,IIS Express默认打开的站点是http://localhost:8080,如果只是本地调试是没有什么问题的。但如果需要联调,则需要将接口开放给其他人员使用,这时其实就需要配置成IP地址。
经过了解,iisexpress的相关配置是放置在目录 C:\Users\系统用户\Documents\IISExpress 下的,在这个目录下有个 config 文件夹,里面有个文件名为 applicationhost.config 的文件,用记事本打开可以进行编辑。
<site name="demo01" id="8">
<application path="/" applicationPool="Clr2IntegratedAppPool">
<virtualDirectory path="/" physicalPath="E:\code\project\demo01" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:8080:localhost" />
</bindings>
</site>
这里可以看到 bindingInformation 的属性,将 localhost 修改成需要的IP地址即可,修改后如下:
<site name="demo01" id="8">
<application path="/" applicationPool="Clr2IntegratedAppPool">
<virtualDirectory path="/" physicalPath="E:\code\project\demo01" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:8080:192.168.0.100" />
</bindings>
</site>
然后再运行一下,在浏览器中输入 http://192.168.0.100:8080,就能正常访问了。
不过如果本机打开了防火墙,记得将8080端口打开一下,要不然还是访问不了的,切忌哦~!