【點滴積累】使用IIS Express

來源:互聯網
上載者:User
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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.