如何允许IISExpress开放外部访问(git版本管理下)
一、 [环境]
1.开发机操作系统 Windows 10 企业版 64位
使用Wifi上网,网卡绑定地址 IP: 192.168.88.238
2. VS版本 visual studio 2015 u2 (注意:要以管理员权限运行!)
3. 使用了git 做为 项目管理
3. 示例开发的解决方案
物理地址: E: estwebEmpty
项目URL: http://localhost:51715/
二、操作步骤
1.IISEXPRESS不能外部访问的现象
2. 找到IISEXPRESS 的配置文件
通过
显示
点击配置上的信息,得到IISEXPRESS的配置文件 E: estWebEmpty.vsconfigapplicationhost.config
3.设置 IISEXPRESS 的配置文件 打开文件后,找到项目的配置节<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: estWebEmptyWeb" /> </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地址 (尝试过打开所有网卡接口,设置为0.0.0.0,但没有效果,谁懂的可教我)
新增后的效果:
<site name="Web" id="2"> <application path="/" applicationPool="Clr4IntegratedAppPool"> <virtualDirectory path="/" physicalPath="E: estWebEmptyWeb" /> </application> <bindings> <binding protocol="http" bindingInformation="*:51715:localhost" /> <binding protocol="http" bindingInformation="*:51715:192.168.167.46" /> </bindings> </site>
4.添加 系统的 URL访问控制列表 以管理员身份运行 cmd,执行以下命令:
netsh http add urlacl url=http://192.168.167.46:51715/ user=everyone
作用(估计): 现在windows操作系统为了安全,在充当服务器用后,在应用层上的服务,也必须显式配置访问白名单
5. 开放防火墙例外或关闭防火墙 根据你系统是处在 公用专用域这几个接口,配置 打开 入站的ICMP v4 就可以了, 如果你像我现在这样,访问的机器还要跨本地网络,还要设置 远程访问为任何. 5.1 检查防火墙接口类型
5.3 如果你还想让局域网外的客户访问,还需要进一步设置,远程访问的作用域
6.重启IISEXPRESS并启动项目 在系统桌面任务栏
7.使用客户机(局域网外的)访问测试
三、常见问题与帮助 1.未成功时访问可能会出现的现象 1.1
Bad Request - Invalid Hostname
HTTP Error 400. The request hostname is invalid.
解决办法:尝试用管理员权限运行vs
2.如何获取网卡IP地址 3.常用工具或命令的使用 4.如何测试防火墙阻挡访问 5.如何检查URL访问控制列表是否已添加及删除 6.其它 (第三点陆继写了,视大家情况再决定如何写!) 四、参考本文受到以下文章内容的帮助:
参考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