一、 [环境]
1.开发机操作系统 Windows 10 企业版 64位
使用Wifi上网,网卡绑定地址 IP: 192.168.88.238
2. VS版本 visual studio 2015 u2 (注意:要以管理员权限运行!)
3. 使用了git 做为 项目管理
3. 示例开发的解决方案
物理地址: E:\test\webEmpty
项目URL: http://localhost:51715/
二、操作步骤
1.IISEXPRESS不能外部访问的现象
2. 找到IISEXPRESS 的配置文件
通过
显示
点击配置上的信息,得到IISEXPRESS的配置文件 E:\test\WebEmpty\.vs\config\applicationhost.config
<sites>
<site name="WebSite1" id="1" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":8080:localhost" />
</bindings>
</site>
<site name="Web" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="E:\test\WebEmpty\Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:51715:localhost" />
</bindings>
</site>
<sites>
<binding protocol="http" bindingInformation="*:51715:localhost" />
加在其后,内容改为:
<binding protocol="http" bindingInformation="*:51715:192.168.167.46" />
其中 192.168.167.46 是你客户机可以访问到的 开发机的网卡接口上的IP地址
<site name="Web" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="E:\test\WebEmpty\Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:51715:localhost" />
<binding protocol="http" bindingInformation="*:51715:192.168.167.46" />
</bindings>
</site>
netsh http add urlacl url=http://192.168.167.46:51715/ user=everyone
Bad Request - Invalid Hostname
HTTP Error 400. The request hostname is invalid.
解决办法:尝试用管理员权限运行vs
本文受到以下文章内容的帮助:
参考1. 配置IISExpress允许外部访问 http://blog.csdn.net/zhangjk1993/article/details/36671105
参考2. 使用netsh命令导致VS调试无法连接配置服务器 http://blog.csdn.net/langyuewu/article/details/39709889
参考3. C# 利用HttpListener监听处理Http请求 http://blog.sina.com.cn/s/blog_6f3ff2c90101wwh5.html