您的位置:首页 > 编程语言 > ASP

IIS Express 开发外部访问

2016-09-12 11:12 197 查看
转载: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

 





<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>  

 复制

[html] view
plain copy

 





<binding protocol="http" bindingInformation="*:51715:localhost" />      

 加在其后,内容改为:
   

[html] view
plain copy

 





<binding protocol="http" bindingInformation="*:51715:192.168.167.46" />  

其中 192.168.167.46 是你客户机可以访问到的 开发机的网卡接口上的IP地址
(尝试过打开所有网卡接口,设置为0.0.0.0,但没有效果,谁懂的可教我)

新增后的效果:
        

[html] view
plain copy

 





    <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>  

           4.添加 系统的 URL访问控制列表
                  以管理员身份运行 cmd,执行以下命令:
        

[plain] view
plain copy

 





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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息