IIS Express 开发外部访问

转载:http://blog.csdn.net/egman/article/details/51991249


一、 [环境] 

            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


          3.设置 IISEXPRESS 的配置文件
                打开文件后,找到项目的配置节
                   
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <sites>  
  2.           <site name="WebSite1" id="1" serverAutoStart="true">  
  3.               <application path="/">  
  4.                   <virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" />  
  5.               </application>  
  6.               <bindings>  
  7.                   <binding protocol="http" bindingInformation=":8080:localhost" />  
  8.               </bindings>  
  9.           </site>  
  10.    <site name="Web" id="2">  
  11.               <application path="/" applicationPool="Clr4IntegratedAppPool">  
  12.                   <virtualDirectory path="/" physicalPath="E:\test\WebEmpty\Web" />  
  13.               </application>  
  14.               <bindings>  
  15.                   <binding protocol="http" bindingInformation="*:51715:localhost" />                    
  16.               </bindings>  
  17.          </site>  
  18. <sites>  

 复制
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <binding protocol="http" bindingInformation="*:51715:localhost" />      

 加在其后,内容改为:
   
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <binding protocol="http" bindingInformation="*:51715:192.168.167.46" />  
其中 192.168.167.46 是你客户机可以访问到的 开发机的网卡接口上的IP地址
(尝试过打开所有网卡接口,设置为0.0.0.0,但没有效果,谁懂的可教我)

新增后的效果:
        
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1.     <site name="Web" id="2">  
  2.           <application path="/" applicationPool="Clr4IntegratedAppPool">  
  3.               <virtualDirectory path="/" physicalPath="E:\test\WebEmpty\Web" />  
  4.           </application>  
  5.           <bindings>  
  6.               <binding protocol="http" bindingInformation="*:51715:localhost" />            
  7. <binding protocol="http" bindingInformation="*:51715:192.168.167.46" />  
  8.           </bindings>  
  9.     </site>  


           4.添加 系统的 URL访问控制列表
                  以管理员身份运行 cmd,执行以下命令:
        
[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. netsh http add urlacl url=http://192.168.167.46:51715/ user=everyone  

作用(估计): 现在windows操作系统为了安全,在充当服务器用后,在应用层上的服务,也必须显式配置访问白名单  

           5. 开放防火墙例外或关闭防火墙
                根据你系统是处在 公用\专用\域这几个接口,配置 打开 入站的ICMP v4 就可以了,
如果你像我现在这样,访问的机器还要跨本地网络,还要设置 远程访问为任何.
           5.1 检查防火墙接口类型
           
           5.2 创建入站规则 (开放TCP 51715 端口)
               

                
         
                5.3 如果你还想让局域网外的客户访问,还需要进一步设置,远程访问的作用域
                        
                           
(比如在开ping 功能时, 搞了半天,局域网外的机子均ping不通主机,原来就是ICMP v4 设置远程地址 默认值是 本地子网)

           6.重启IISEXPRESS并启动项目
                   在系统桌面任务栏  , 停止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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值