部署ASP.net MVC程序到IIS

转:http://www.cnblogs.com/piyeyong/archive/2012/08/15/2640004.html

在网上找到一个table,列举了不同的操作系统对应的IIS版本以及配置MVC时的说明。

IIS version

Windows version

Remarks

IIS 7.0 (integrated mode)

Windows Server 2008

Windows Vista (except Home Basic)

No special configuration required

IIS 7.0 (classic mode)

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.NETFramework64v4.0.30319aspnet_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

原文地址:https://www.cnblogs.com/jackljf/p/4768576.html