How to set an Orchard CMS module to be home page with code

This will work for Orchard CMS Version 1.8.

  • Create a new module
  • Create a Routes.cs file in the module
  • Set the RouteDescriptor priority to something high like 99
  • Set the new route url to be an empty string

Here’s some example code for Routes.cs

using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.Mvc.Routes;

namespace Newmodule
{
    public class Routes : IRouteProvider
    {
        public void GetRoutes(ICollection<RouteDescriptor> routes)
        {
            foreach (var routeDescriptor in GetRoutes())
                routes.Add(routeDescriptor);
        }

        public IEnumerable<RouteDescriptor> GetRoutes()
        {
            return new[] {

                new RouteDescriptor {
                    Priority = 99,
                    Route = new Route( 
			"",
                        new RouteValueDictionary {
                            {"area", "Newmodule"},
                            {"controller", "Home"},
                            {"action", "Index"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "Newmodule"}
                        },
                        new MvcRouteHandler())
                }



            };
        }
    }
}

Advertisements

One thought on “How to set an Orchard CMS module to be home page with code

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s