RSS

Monthly Archives: December 2010

Deploying an MVC 2 ASP.NET application in IIS 7.5

 So whats it all about?

 Having been subjected to the previous n-tier, highly coupled, impossible to maintain architecture that makes up one of our software applications for far too long, a development decision was made to move into the MVC arena.  However having done all the hard work of integrating the MVC framework into an existing ASP.NET Forms application (which was actually very straightforward), what worked fine in the Visual Studio IDE, failed miserably when I published to IIS.

So if like me you had an existing Web Forms application into which you have integrated the new MVC 2.0 framework and are about to publish to IIS (I’m using IIS 7.5) then this handy little checklist may be of help.  Or if you have already published and are sitting looking at the following IIS error then this post will definately be of help;

Routing Error - 404 Page not found

 

 

 

  

1. Make sure you Routing is set up correctly

Firstly, assuming your MVC application is running correctly in the IDE, its worth double checking the Routing is configured correctly prior to deployment else you will more than likely end up with the dreaded 404 page not found error.

Your Routing rules should be registered in the Global.asax.cs file within the RegisterRoutes method or the Application_start method

RegisterRoutes method located in Global.asax.cs

 

 2. web.config alterations

Now if you used the template provided by Visual Studio to create your MVC application then chances are your web.config file will contain everything you need, however if like me you are adding MVC to an existing Web Forms application then there are a few bits you need to consider:

Firstly this is the one that caught me out

Assembly Binding for System.Web.MVC DLL

you will need to add this binding information to ensure you are using the correct MVC 2.0 assembly.  Also add the following runAllManagedModulesForAllRequests attribute to the modules section and set to True.  Additionally ensure the Modules section points to the correct UrlRoutingModule assembly (version 4.0.0.0 or 3.5.0.0 depending on your framework)

Adding the correct modules and the runAllManagedModulesForAllRequests attribute

 

 

 

 

 

Note: (If you have you application running through the IDE then chances are that the next few points regarding the web.config are already in place)

Now if your using Framework 4 then Microsoft have made things a little easier, reasons being that the Web.config was cleaned up for the ASP.NET 4.0 release and you only have to add assembly references for:

  • System.web.Abstractions
  • System.Web.Routing
  • System.web.MVC

Assembly References for MVC 2.0

 

If however you are using Framework 3.5 you will need to ensure you have references to the following extra assemblies:

  • system.Core
  • System.Data.DataSetExtensions
  • System.Web.Extensions
  • System.XML.Linq

Also ensure that you have the following namespaces defined in the web.config

Namespaces required for MVC in the web.config

Once again if you are using Framework 3.5 then you will need these extra namespaces
  • System.Linq
  • System.Collections.Generic
3. Configuring IIS
 
So your application is ready and your web.config is ready, all thats required now is to ensure IIS is configured to host your MVC application.If you are using Framework 4.0 then ensure that you have registered/installed the ASP.NET Framework against IIS:
 
Navigate to the correct location normally ‘C:\Windows\Microsoft.NET\Framework\v4.0.30319’
and type aspnet_regiis.exe -i
  
Next load the IIS Manager and Invoke the ISAPI and CGI Restrictions window and allow ASP.NET version 4.0.30319
 

ISAPI and CGI Restrictions

 
 
Create or choose an existing Application Pool to house your application but make sure the Managed pipeline mode is set to IntegratedApplication Pool
 

Application Pool

 
 
 Finally you may need to drill into the Advanced Settings of the application pool and set ‘Enable 32-bit Applications’ to True and Set the ‘Identity‘ to Network Service

Advanced Settings of the App Pool

Right, thats it, your MVC application should now work just as well under IIS as it did through the Visual Studio IDE.  If theres something I’ve missed then let me know and I’ll amend the post, but hope it helps.
Advertisements
 
Leave a comment

Posted by on December 2, 2010 in Uncategorized