将ASP.NET MVC应用程序部署到IIS7并保持干净的web.config

时间:2021-07-24 20:09:30

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应用程序部署到Web托管公司(如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的最佳方法是什么?

4 个解决方案

#1


6  

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

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

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只需要包含我的简单应用程序设置。

#2


3  

.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设置。

#3


2  

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,请随意删除它们。

#4


1  

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.

最好的方法是始终拥有一个尽可能接近镜像生产环境的开发环境 - 您不希望以这种方式编辑生产配置。

#1


6  

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

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

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只需要包含我的简单应用程序设置。

#2


3  

.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设置。

#3


2  

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,请随意删除它们。

#4


1  

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.

最好的方法是始终拥有一个尽可能接近镜像生产环境的开发环境 - 您不希望以这种方式编辑生产配置。