现在的位置: 首页 > 综合 > 正文

【点滴积累】使用IIS Express

2013年09月29日 ⁄ 综合 ⁄ 共 2812字 ⁄ 字号 评论关闭

1.IIS Express 概述

IIS Express是一个微软推出的一款免费,且小型、轻量特别适合ASP.NET开发人员使用的Web开发服务器。在没有IIS Express之前,开发人员只能使用下面两种方案:

  • Visual Studio自带的ASP.NET开发服务器
  • Windows的IIS Web服务器

既然已经有了这两个选择,为什么还要推出IIS Express呢?这是由于这两个方案的不足决定的,如下:

  • Visual Studio自带的Web服务器并没有提供完整的Web服务器功能(例如:不支持SSL、URL重写规则等)
  • Visual Studio自带的Web服务器并不支持外部访问
  • 使用IIS首先需要管理员账号来安装和调试
  • 不同版本的Windows对支持IIS的版本也不相同(Windows XP就不能使用IIS7.x的新功能)

但是IIS Express集成了这两种方案的优点,又避免的他们的缺点

  • 首先,IIS Express除了没有IIS的可视化管理界面,几乎用于其全部的功能
  • 其次,IIS Express经过简单的配置后也可以在Visual Studio 2010中使用(VS2012已经内置了IIS Express 8)
  • 再者,IIS Express相对于IIS支持更多版本的Windows系统(在Windows XP下可以使用IIS Express 7.5)

 

2.使用IIS Express部署一个Web应用程序

  使用IIS Express部署一个站点非常简单,只需要修改Express的applicationhost.config配置文件即可,该文件用于承载站点的定义、应用程序、应用程序池和整个WEB服务器的配置。文件的默认位置在:C:\Users\UserName(用户名)\Documents\IISExpress\config目录下,打开该配置文件我们可以看到IIS Express支持下面五种应用程序池:分别是.NET 2.0和.NET 4.0的集成版和经典版,以及一个非托管的版本:

1                 <applicationPools>
2                     <add name="Clr4IntegratedAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
3                     <add name="Clr4ClassicAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
4                     <add name="Clr2IntegratedAppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />             
5                     <add name="Clr2ClassicAppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />             
6                     <add name="UnmanagedClassicAppPool" managedRuntimeVersion="" managedPipelineMode="Classic" autoStart="true" /><applicationPoolDefaults managedRuntimeLoader="v4.0">
7                     <processModel />
8                     </applicationPoolDefaults>
9                 </applicationPools>

View Code

  现在我们来看最重要的sites节点,每个site节点表示一个站点,其中:bindingInformation节点由三个部分组成:绑定的IP:端口:主机名称

 1         <sites>
 2             <site name="IIS Express" 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         <sites>

  现在我们可以开始部署Web应用程序了,将发布好的Web应用程序放到指定目录(在我这里我将其放到D盘的WebAPP目录下面),然后修改上面的配置文件,比如选择绑定的端口,选择Web应用程序对于的.NET应用程序池即可:

1             <site name="WebSite" id="2" serverAutoStart="true">
2                 <application path="/" applicationPool="Clr4IntegratedAppPool">
3                     <virtualDirectory path="/" physicalPath="D:\WebApp" />
4                 </application>
5                 <bindings>
6                     <binding protocol="http" bindingInformation="*:8081:*" />
7                 </bindings>
8             </site>

  启动IIS Express,在浏览器中输入:http://localhost:8081/访问Web应用程序:

 

3.配置IIS Express 使其能够进行外部访问

  首先是需要将Web应用程序使用的端口号在Windows防火墙中设置允许通过,其次是修改site节点下的binding节点的bindingInformation属性:

                <bindings>
                    <binding protocol="http" bindingInformation="*:8081:*" />
                </bindings>

最后,需要以管理员身份启动IIS Express即可,使用Ip地址进行访问:

 

参考资料&进一步阅读

http://msdn.microsoft.com/zh-cn/ff844168

http://www.cnblogs.com/nicch/archive/2011/03/20/1989192.html

抱歉!评论已关闭.