轉:http://www.cnblogs.com/piyeyong/archive/2012/08/15/2640004.htmlhtml
在網上找到一個table,列舉了不一樣的操做系統對應的IIS版本以及配置MVC時的說明。web
IIS versionsql |
Windows versionexpress |
Remarkswindows |
IIS 7.0 (integrated mode)瀏覽器 |
Windows Server 2008app Windows Vista (except Home Basic)asp.net |
No special configuration required網站 |
IIS 7.0 (classic mode)ui |
Windows Server 2008 Windows Vista (except Home Basic) |
Special configuration required to use URL routing |
IIS 6.0 |
Windows Server 2003 |
Special configuration required to use URL routing |
IIS 5.1 |
Windows XP Professional |
Special configuration required to use URL routing |
IIS 5.0 |
Windows 2000 |
Special configuration required to use URL routing |
從表中能夠總結出:
1.IIS7.0以前的版本,須要特殊配置,由於現有IIS,後來纔開發的MVC模塊
2.IIS7.0的classic mode,適合以前的版本兼容的,須要特殊配置
3.補充: Windows 7 和window server 2008 R2是IIS7.5,IIS的版本越新,配置越簡單(這個是必然的)
我以爲之後趕上IIS6.0的機會不多了,因此也沒必要理會,只要知道IIS7的Integrated mode如何配置就能夠了。
1.安裝好IIS後,添加一個新的網站:
注意新建的website的binding不要與原有website衝突,Default Web Site使用的80端口。
新建的website都會自動建立App pool,它的做用是隔離其它的App pool,各個web site不會互相影響,一個crash了,其它還能繼續。
2.在Application Pools下編輯剛剛建立的App pool:
這裏選擇.NET的版本和pipeline mode,就是前面說的Integrated mode和classic mode
3.在VS2010中publish
在web project上右鍵,publish
在彈出的Publish Web對話框裏輸入URL和website名,點擊Publish
刷新IIS,能夠看到已經部署成功
4.打開瀏覽器訪問,遇到的問題及解決方案:
出現403.14Forbidden錯誤
須要運行命令:%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir
緣由是先安裝的.net framework,後安裝的iis,須要將asp.net的模塊註冊到IIS
An attempt to attach an auto-named database for file .mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
使用mdf文件而後直接attach到sql server express這種方式的,可能會遇到這個錯誤,這個須要將User Instance=True這個屬性加到connection string中
能夠直接編輯web.config文件,也能夠在IIS的web site的Features View頁面的Connection Strings配置項修改
Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.
須要修改app pool的Identity,換成NewworkService,在App pool的Advanced Settings頁面修改
Windows7的bug
這個是折騰我最久的一個issue,我實在win7開發的,部署後經過瀏覽器始終沒法打開網頁,也看不到任何錯誤。後來在windows server2008 R2上試了下,一點問題木有,後來在《Pro ASP.NET MVC 2 Framework, Second Edition》這本書找到了答案:
If you’re trying to deploy to IIS 7.5 on Windows 7 for development purposes, you may also need to click Start, type turn windows features on or off, press Enter, and then enable Internet Information Services