当你电脑需要从前端访问后端api的时候,有可能牵扯到必须解决跨域问题才能够正常调试,那么你只需要三步:
一、修改applicationhost.config文件中的内容,但是我们会发现这个文件存在于好几个地方,比如:
1、C:\Program Files\IIS Express\AppServer\applicationhost.config
2、C:\Program Files (x86)\IIS Express\AppServer\applicationhost.config
3、C:\Users\用户\Documents\IISExpress\config\applicationhost.config
4、你的xxx项目路径\.vs\mawbocr\config\applicationhost.config
以上我们只需要修改4路径中的内容,其他的不用修改,修改了也无效。首先找到 <bindings></bindings>节点,按如下格式添加,ip和端口改为自己电脑上的。
<bindings>
<binding protocol="https" bindingInformation="*:44361:192.168.4.101" />
<binding protocol="https" bindingInformation="*:44360:localhost" />
<binding protocol="http" bindingInformation="*:3617:localhost" />
</bindings>
二、如果步骤一做完你还不能从通过ip方式访问,且IIS Express中还是看不到ip,需要添加一条命令:
netsh http add urlacl url=https://192.168.4.101:44361/ user=everyone
如果命令有误,可以删除,命令如下:
netsh http delete urlacl url=https://192.168.4.101:44361/
三、如果还是不能访问通,那说明你电脑本身开启了防火墙,阻止了这个端口,添加防火墙规则:
完毕!