【點滴積累】使用IIS Express


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM