部署ASP.net MVC程序到IIS

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

相关文章
相关标签/搜索