using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using System.Web.Routing; namespace Umbraco.Web { internal static class RouteCollectionExtensions { public static void IgnoreStandardExclusions(this RouteCollection routes) { // Ignore standard stuff... using (routes.GetWriteLock()) { var exclusions = new Dictionary() { {"{resource}.axd/{*pathInfo}", null}, {"{*allaxd}", new { allaxd = @".*\.axd(/.*)?" }}, {"{*allashx}", new { allashx = @".*\.ashx(/.*)?" }}, {"{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" }}, {"{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }}, }; //ensure they're not re-added foreach (var e in exclusions.Where(e => !routes.OfType().Any(x => x.Url == e.Key))) { if (e.Value == null) { routes.IgnoreRoute(e.Key); } else { routes.IgnoreRoute(e.Key, e.Value); } } } } /// /// Extension method to manually regsiter an area /// /// /// public static void RegisterArea(this RouteCollection routes) where T : AreaRegistration { // instantiate the area registration var area = Activator.CreateInstance(); // create a context, which is just the name and routes collection var context = new AreaRegistrationContext(area.AreaName, routes); // register it! area.RegisterArea(context); } ///// ///// Extension method to manually regsiter an area from the container ///// ///// ///// ///// //public static void RegisterArea(this RouteCollection routes, Framework.DependencyManagement.IDependencyResolver container) // where T : AreaRegistration //{ // var area = container.Resolve() as AreaRegistration; // if (area == null) // { // throw new InvalidCastException("Could not resolve type " + typeof(T).FullName + " to AreaRegistration"); // } // // create a context, which is just the name and routes collection // var context = new AreaRegistrationContext(area.AreaName, routes); // // register it! // area.RegisterArea(context); //} public static void RegisterArea(this RouteCollection routes, T area) where T : AreaRegistration { area.RegisterArea(new AreaRegistrationContext(area.AreaName, routes)); } } }