asp.net-mvc 将 ASP.NET MVC 应用程序部署到 IIS7 并保持干净的 web.config
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/579107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deploying an ASP.NET MVC app to IIS7 and keeping a clean web.config
提问by Ben Mills
I'd like to deploy my ASP.NET MVC application to a web hosting company (like DiscountASP.net). I'm confused about what needs to be in the web.config file on the web server. When I create the project locally, I get a bloated web.config with all sorts of additional modules, handlers, compilers. Do I need to add all these items to the production web.config file?
我想将我的 ASP.NET MVC 应用程序部署到网络托管公司(如 DiscountASP.net)。我对 Web 服务器上的 web.config 文件中需要包含的内容感到困惑。当我在本地创建项目时,我会得到一个臃肿的 web.config,其中包含各种附加模块、处理程序、编译器。我是否需要将所有这些项目添加到生产 web.config 文件中?
I'm still deploying my current ASP.NET application (not MVC) in IIS6 and I've always hand crafted a simple web.config for the production environment and uploaded it with the rest of the application files. It seems like with IIS7 I'm meant to use the IIS Manager on the web server to build the web.config. What's the best way to build/manage the web.config on a production server?
我仍然在 IIS6 中部署我当前的 ASP.NET 应用程序(不是 MVC),我总是为生产环境手工制作一个简单的 web.config,并将它与其余的应用程序文件一起上传。似乎对于 IIS7,我打算使用 Web 服务器上的 IIS 管理器来构建 web.config。在生产服务器上构建/管理 web.config 的最佳方法是什么?
采纳答案by Ben Mills
So here's what I've found so far trying to deploy my MVC application to DiscountASP.net.
所以这是我到目前为止尝试将我的 MVC 应用程序部署到 DiscountASP.net 时所发现的。
The first think I found was that I had to make sure that System.Web.Mvc was deployed to the bin as it's not installed in the GAC:
我发现的第一个想法是我必须确保 System.Web.Mvc 已部署到 bin 中,因为它没有安装在 GAC 中:
http://haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx
http://haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx
Then I started with a super basic web.config that just contained the database connection string. My application did not work.
然后我从一个超级基本的 web.config 开始,它只包含数据库连接字符串。我的应用程序不起作用。
Then I copied the mess that's my local web.config up to the server and changed the database connection string and things started to work, but I was still getting the error message:
然后我将我本地 web.config 的混乱复制到服务器并更改了数据库连接字符串,事情开始工作,但我仍然收到错误消息:
Could not load type 'System.Web.Mvc.ViewPage<MyCustomModel>'
Then I found this article that explains how you need to change the web.config to support not using code behind files (you don't need to do this with the local Visual Studio web server for some reason):
然后我发现这篇文章解释了如何更改 web.config 以支持不使用代码隐藏文件(出于某种原因,您不需要使用本地 Visual Studio Web 服务器执行此操作):
http://blog.benhall.me.uk/2009/01/aspnet-mvc-rc1-removing-code-behind.html
http://blog.benhall.me.uk/2009/01/aspnet-mvc-rc1-removing-code-behind.html
Personally, I don't like how simple application settings such as connection strings and SMTP settings are getting mixed in with complex MVC (and AJAX.NET) infrastructure settings. One nice option would be for the hosting company (such as DiscountASP.net) to set up the Master.config (or a higher level web.config) to support MVC, so that my web.config would only need to contain my simple application settings.
就我个人而言,我不喜欢将简单的应用程序设置(例如连接字符串和 SMTP 设置)与复杂的 MVC(和 AJAX.NET)基础设施设置混在一起。一个不错的选择是托管公司(例如 DiscountASP.net)设置 Master.config(或更高级别的 web.config)以支持 MVC,这样我的 web.config 只需要包含我的简单应用程序设置。
回答by David
.Net 3.5 and IIS7 both add quite a bit of text to the web.config. What I do is use the IIS Manager in IIS7 to configure the app once. Then I take that modified web.config and check it back in to source control. That way all of the IIS settings are preserved when migrating between environments.
.Net 3.5 和 IIS7 都向 web.config 添加了相当多的文本。我所做的是使用 IIS7 中的 IIS 管理器来配置应用程序一次。然后我将修改后的 web.config 重新签入源代码管理。这样,在环境之间迁移时,所有 IIS 设置都会保留。
回答by Peter Seale
System.Web.Extensions is the MS AJAX AKA Atlas stuff, there are several modules and handlers and sections associated with this assembly. Feel free to remove them if you're not using the MS AJAX stuff.
System.Web.Extensions 是 MS AJAX AKA Atlas 的东西,有几个模块和处理程序以及与这个程序集相关的部分。如果您不使用 MS AJAX 的东西,请随意删除它们。
回答by Andrew Hare
Perhaps you take a search-and-destroy approach and chip away at the config until you have removed everything you don't need. Without knowing your application and its dependencies it is difficult to say what you may or may not need.
也许您采用搜索和破坏的方法并削减配置,直到您删除了不需要的所有内容。在不了解您的应用程序及其依赖项的情况下,很难说出您可能需要或不需要什么。
The best approach is to always have a development environment that mirrors your production environment as closely as possible - you don't want to be editing production configs in this way.
最好的方法是始终拥有一个尽可能接近您的生产环境的开发环境 - 您不希望以这种方式编辑生产配置。

