From 89434ea16eba306b670cea68e006179e7eeb0363 Mon Sep 17 00:00:00 2001 From: Uncled1023 Date: Tue, 24 Nov 2015 10:12:08 -0800 Subject: [PATCH] Updated Routing to allow defining the Area. Modified loading of scripts to move some to end of body. --- Teknik/App_Start/SubdomainRouteExtension.cs | 42 +++++++++++++++++++ Teknik/Areas/About/AboutAreaRegistration.cs | 4 +- Teknik/Areas/Blog/BlogAreaRegistration.cs | 23 +--------- .../Areas/Contact/ContactAreaRegistration.cs | 4 +- Teknik/Areas/Dev/DevAreaRegistration.cs | 15 +++---- Teknik/Areas/Home/HomeAreaRegistration.cs | 12 ++---- Teknik/Areas/Home/Scripts/Home.js | 1 + Teknik/Areas/Home/Views/Home/Index.cshtml | 1 - .../Areas/Privacy/PrivacyAreaRegistration.cs | 4 +- Teknik/Teknik.csproj | 1 + Teknik/Views/Shared/_Layout.cshtml | 10 ++--- 11 files changed, 66 insertions(+), 51 deletions(-) create mode 100644 Teknik/Areas/Home/Scripts/Home.js diff --git a/Teknik/App_Start/SubdomainRouteExtension.cs b/Teknik/App_Start/SubdomainRouteExtension.cs index f66ddd8..cb88387 100644 --- a/Teknik/App_Start/SubdomainRouteExtension.cs +++ b/Teknik/App_Start/SubdomainRouteExtension.cs @@ -83,5 +83,47 @@ namespace Teknik context.Routes.Add(name, route); return route; } + + public static SubdomainRoute MapSubdomainRoute(this AreaRegistrationContext context, string name, string subDomain, string url, string area, object defaults) + { + SubdomainRoute route = new SubdomainRoute( + subDomain, + url, + new RouteValueDictionary(defaults), + new RouteValueDictionary(new { }), + new RouteValueDictionary(new { Area = area }), + new MvcRouteHandler()); + + context.Routes.Add(name, route); + return route; + } + + public static SubdomainRoute MapSubdomainRoute(this AreaRegistrationContext context, string name, string subDomain, string url, string area, object defaults, object constraints) + { + SubdomainRoute route = new SubdomainRoute( + subDomain, + url, + new RouteValueDictionary(defaults), + new RouteValueDictionary(constraints), + new RouteValueDictionary(new { Area = area }), + new MvcRouteHandler()); + + context.Routes.Add(name, route); + return route; + } + + public static SubdomainRoute MapSubdomainRoute(this AreaRegistrationContext context, string name, string subDomain, string url, string area, object defaults, string[] namespaces) + { + SubdomainRoute route = new SubdomainRoute( + subDomain, + url, + new RouteValueDictionary(defaults), + new RouteValueDictionary(new { }), + new RouteValueDictionary(new { Area = area, Namespaces = namespaces }), + new MvcRouteHandler()); + + context.Routes.Add(name, route); + return route; + } } } \ No newline at end of file diff --git a/Teknik/Areas/About/AboutAreaRegistration.cs b/Teknik/Areas/About/AboutAreaRegistration.cs index feae6a9..dc29d6e 100644 --- a/Teknik/Areas/About/AboutAreaRegistration.cs +++ b/Teknik/Areas/About/AboutAreaRegistration.cs @@ -18,14 +18,14 @@ namespace Teknik.Areas.About "About_dev", // Route name "dev", "About/{controller}/{action}", // URL with parameters - new { area = "About", controller = "About", action = "Index" }, // Parameter defaults + new { controller = "About", action = "Index" }, // Parameter defaults new[] { typeof(Controllers.AboutController).Namespace } ); context.MapSubdomainRoute( "About_default", // Route name "about", "{controller}/{action}", // URL with parameters - new { area = this.AreaName, controller = "About", action = "Index", username = UrlParameter.Optional, page = UrlParameter.Optional }, // Parameter defaults + new { controller = "About", action = "Index" }, // Parameter defaults new[] { typeof(Controllers.AboutController).Namespace } ); } diff --git a/Teknik/Areas/Blog/BlogAreaRegistration.cs b/Teknik/Areas/Blog/BlogAreaRegistration.cs index f4f5bec..a5ff10f 100644 --- a/Teknik/Areas/Blog/BlogAreaRegistration.cs +++ b/Teknik/Areas/Blog/BlogAreaRegistration.cs @@ -14,37 +14,18 @@ namespace Teknik.Areas.Blog public override void RegisterArea(AreaRegistrationContext context) { - //context.MapSubdomainRoute( - // "Blog_dev", // Route name - // "dev", - // "blog/{controller}/{action}/{username}/{page}", // URL with parameters - // new { subdomain = "blog", area = this.AreaName, controller = "Blog", action = "Index", username = UrlParameter.Optional, page = UrlParameter.Optional } // Parameter defaults - // ); context.MapSubdomainRoute( "Blog_dev", // Route name "dev", "Blog/{controller}/{action}", // URL with parameters - new { area = "Blog", controller = "Blog", action = "Index" } // Parameter defaults + new { controller = "Blog", action = "Index" } // Parameter defaults ); context.MapSubdomainRoute( "Blog_default", // Route name "blog", "{controller}/{action}/{username}/{page}", // URL with parameters - new { area = this.AreaName, controller = "Blog", action = "Index", username = UrlParameter.Optional, page = UrlParameter.Optional } // Parameter defaults + new { controller = "Blog", action = "Index", username = UrlParameter.Optional, page = UrlParameter.Optional } // Parameter defaults ); - //context.Routes.MapSubDomainRoute( - // "Blog_default", // Route name - // "blog", // Domain with parameters - // "{controller}/{action}", // URL with parameters - // new { controller = "Blog", action = "Index" }, // Parameter defaults - // new[] { typeof(Controllers.BlogController).Namespace } - // ); - //context.MapRoute( - // "Blog_default", - // "{subdomain}/{controller}/{action}/{username}/{page}", - // new { subdomain = "blog", controller = "Blog", action = "Index", username = UrlParameter.Optional, page = UrlParameter.Optional }, - // namespaces: new[] { "Teknik.Areas.Blog.Controllers" } - //); } } } \ No newline at end of file diff --git a/Teknik/Areas/Contact/ContactAreaRegistration.cs b/Teknik/Areas/Contact/ContactAreaRegistration.cs index 8360f3e..417de37 100644 --- a/Teknik/Areas/Contact/ContactAreaRegistration.cs +++ b/Teknik/Areas/Contact/ContactAreaRegistration.cs @@ -18,14 +18,14 @@ namespace Teknik.Areas.Contact "Contact_dev", // Route name "dev", "Contact/{controller}/{action}", // URL with parameters - new { area = this.AreaName, controller = "Contact", action = "Index" }, // Parameter defaults + new { controller = "Contact", action = "Index" }, // Parameter defaults new[] { typeof(Controllers.ContactController).Namespace } ); context.MapSubdomainRoute( "Contact_default", // Route name "contact", "{controller}/{action}", // URL with parameters - new { area = this.AreaName, controller = "Contact", action = "Index" }, // Parameter defaults + new { controller = "Contact", action = "Index" }, // Parameter defaults new[] { typeof(Controllers.ContactController).Namespace } ); } diff --git a/Teknik/Areas/Dev/DevAreaRegistration.cs b/Teknik/Areas/Dev/DevAreaRegistration.cs index d225234..7be6821 100644 --- a/Teknik/Areas/Dev/DevAreaRegistration.cs +++ b/Teknik/Areas/Dev/DevAreaRegistration.cs @@ -1,4 +1,5 @@ using System.Web.Mvc; +using Teknik.Areas.Home.Controllers; namespace Teknik.Areas.Dev { @@ -14,25 +15,21 @@ namespace Teknik.Areas.Dev public override void RegisterArea(AreaRegistrationContext context) { - //Config config = Config.Load(); context.MapSubdomainRoute( "Dev_subdomain", // Route name "dev", "Dev/{controller}/{action}", // URL with parameters - new { area = "Dev", controller = "Dev", action = "Index" } // Parameter defaults + new { controller = "Dev", action = "Index" }, // Parameter defaults + new[] { typeof(Controllers.DevController).Namespace } ); context.MapSubdomainRoute( "Dev_default", // Route name "dev", "", // URL with parameters - new { area = "Home", controller = "Home", action = "Index" } // Parameter defaults + "Home", + new { controller = "Home", action = "Index" }, // Parameter defaults + new[] { typeof(HomeController).Namespace } ); - //context.MapRoute( - // "Dev_default", - // "Dev/{controller}/{action}", - // new { controller = "Dev", action = "Index" }, - // namespaces: new[] { "Teknik.Areas.Dev.Controllers" } - //); } } } \ No newline at end of file diff --git a/Teknik/Areas/Home/HomeAreaRegistration.cs b/Teknik/Areas/Home/HomeAreaRegistration.cs index d5e119c..ecd752e 100644 --- a/Teknik/Areas/Home/HomeAreaRegistration.cs +++ b/Teknik/Areas/Home/HomeAreaRegistration.cs @@ -19,29 +19,23 @@ namespace Teknik.Areas.Home "Home_dev", // Route name "dev", "Home/{controller}/{action}", // URL with parameters - new { area = "Home", controller = "Home", action = "Index" }, // Parameter defaults + new { controller = "Home", action = "Index" }, // Parameter defaults new[] { typeof(Controllers.HomeController).Namespace } ); context.MapSubdomainRoute( "Home_subdomain", // Route name "www", "{controller}/{action}", // URL with parameters - new { area = this.AreaName, controller = "Home", action = "Index" }, // Parameter defaults + new { controller = "Home", action = "Index" }, // Parameter defaults new[] { typeof(Controllers.HomeController).Namespace } ); context.MapSubdomainRoute( "Home_default", // Route name null, "{controller}/{action}", // URL with parameters - new { area = this.AreaName, controller = "Home", action = "Index" }, // Parameter defaults + new { controller = "Home", action = "Index" }, // Parameter defaults new[] { typeof(Controllers.HomeController).Namespace } ); - //context.MapRoute( - // "Home_default", - // "{controller}/{action}", - // new { area = "Home", controller = "Home", action = "Index" }, - // namespaces: new[] { "Teknik.Areas.Home.Controllers" } - //); } } } \ No newline at end of file diff --git a/Teknik/Areas/Home/Scripts/Home.js b/Teknik/Areas/Home/Scripts/Home.js new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Teknik/Areas/Home/Scripts/Home.js @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Teknik/Areas/Home/Views/Home/Index.cshtml b/Teknik/Areas/Home/Views/Home/Index.cshtml index fca3501..2f9523b 100644 --- a/Teknik/Areas/Home/Views/Home/Index.cshtml +++ b/Teknik/Areas/Home/Views/Home/Index.cshtml @@ -126,7 +126,6 @@