views:

7231

answers:

4

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?

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?

+1  A: 

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.

Andrew Hare
Let's say I have a very simple application and the only thing I've added to the web.config is a database connection string. Do I need to get all the handlers, modules and compilers into the web.config or will this information be in the machine.config already?
Ben Mills
You ought to be able to strip the other stuff out but as you are using MVC there may be handlers and modules that are required for MVC to work. The best thing I can tell you is to test this locally until you have a stripped down config to deploy.
Andrew Hare
+3  A: 

.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.

David
I feel like the web.config has been filling up with junk. It's getting really hard to keep track of what it's all for.
Ben Mills
+2  A: 

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.

Peter Seale
Not sure why that was voted down, just removed a ton of junk from my web config from that suggestion...
rball
+5  A: 

So here's what I've found so far trying to deploy my MVC application to 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:

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.

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:

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

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.

Ben Mills