Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying an ASP.NET MVC app to IIS7 and keeping a clean web.config

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?

like image 703
Ben Mills Avatar asked Feb 23 '09 20:02

Ben Mills


People also ask

Is it true that MVC itself hosted on an IIS server and a self Userpipeline?

Net Pipeline, on the other hand MVC 6 has a feature that makes it better and that feature is itself hosted on an IIS server and a self-user pipeline. The configuration system provides an environment to easily deploy the application on the cloud. Our application works just like a configuration provider.

How do I deploy .NET MVC to IIS?

Right-click on your ASP.NET MVC5 application inside Visual Studio and then click "Publish". Now, select the "IIS" option from the left menu and click "Create Profile" button. Change your publish method to "Web Deploy Package" and provide your package location, then click "Next". Click "Save" on the next screen.


2 Answers

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.

like image 166
Ben Mills Avatar answered Nov 15 '22 06:11

Ben Mills


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

like image 23
David Avatar answered Nov 15 '22 06:11

David