posts - 76, comments - 26, trackbacks - 0

Monday, February 01, 2010

Deploying ASP.NET MVC Apps to Shared Hosting Providers – Webhost4life.com

Are you getting 404’s on your deployed site when it works perfectly on your development machine?

There’s a number of hidden gotchas when deploying an ASP.NET MVC application to a shared hosting providers.  My provider of choice is Webhost4life.com.  Here’s a list of issues I ran into and the solutions for each.

IIS 6.0 vs IIS 7.0

There’s a number of issues you need to be aware of here.  If you using IIS 6 -- and if you’re on Webhost4life there’s a good chance you are – then you need to make sure you’re virtual directory is configured w/ the “Wildcard application map” ISAPI setup that Phil talks about in his ASP.NET MVC on IIS 6 Walkthrough post.  The short answer is – you have to contact Webhost4life to do this.  As of this writing, this is not available through their Control Panel.

MVC Binaries

As of this writing, Webhost4life.com does not have ASP.NET MVC installed on their servers and therefore none of the assemblies are installed in the GAC.  At a minimum, you need to bin deploy System.Web.Mvc.dll assembly.  Follow the instructions from Phil on how to do this in his post Bin Deploying ASP.NET MVC – the abbreviated version is:  mark the references to MVC assemblies in your project as CopyLocal=true.

Route Setup

Make sure that your routes our setup in a way that jives with your domain.  In other words, make sure that http://www.yourdomain.com/ will go to the proper route.  This is easy to overlook since your Startup Page in Visual Studio is set to something like /Site/Home while debugging. However, this isn’t how people are going to navigate to your site on your hosting provider.  In my case I setup routes with the code below.  This allows folks coming into my site via http://yourdomain.com and http://yourdomain.com/Site/Home to all end up in the same place

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute("Default", "{controller}/{action}/{id}",  new { controller = "Site", action = "Home", id = "" });
            routes.MapRoute("Root", "", new { controller = "Site", action = "Home", id = "" } );
        }

        protected void Application_Start()
        {
            Global.RuntimeSettings = new RuntimeSettings {MachineName = base.Context.Server.MachineName};
            RegisterRoutes(RouteTable.Routes);
        }
    }

Link Round Up

Here’s a list of things I found helpful when debugging this stuff

posted @ Monday, February 01, 2010 6:18 AM | Feedback (0) | Filed Under [ .net ]

Powered by: