From 1d8c4fba343e76f7eeb3651f7f43061cc19408ab Mon Sep 17 00:00:00 2001 From: Uncled1023 Date: Wed, 16 Dec 2015 16:57:24 -0800 Subject: [PATCH] Modified routing to better match real URL. --- Teknik/Areas/Blog/BlogAreaRegistration.cs | 31 ++++++++++++++----- .../Areas/Blog/Controllers/BlogController.cs | 21 +++++++------ .../Areas/Contact/ContactAreaRegistration.cs | 4 +-- .../Areas/Profile/ProfileAreaRegistration.cs | 4 +-- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Teknik/Areas/Blog/BlogAreaRegistration.cs b/Teknik/Areas/Blog/BlogAreaRegistration.cs index 6ce02af..279dd34 100644 --- a/Teknik/Areas/Blog/BlogAreaRegistration.cs +++ b/Teknik/Areas/Blog/BlogAreaRegistration.cs @@ -13,23 +13,40 @@ namespace Teknik.Areas.Blog } } - public override void RegisterArea(AreaRegistrationContext context) + public override void RegisterArea(AreaRegistrationContext context) { context.MapSubdomainRoute( - "Blog_dev", // Route name + "Blog_dev_index", // Route name "dev", - "Blog/{controller}/{action}/{username}/{id}", // URL with parameters - new { controller = "Blog", action = "Index", username = UrlParameter.Optional, id = UrlParameter.Optional } // Parameter defaults + "Blog", // URL with parameters + new { controller = "Blog", action = "Index" }, // Parameter defaults + new[] { typeof(Controllers.BlogController).Namespace } ); context.MapSubdomainRoute( - "Blog_default", // Route name + "Blog_dev_detail", // Route name + "dev", + "Blog/{username}/{id}", // URL with parameters + new { controller = "Blog", action = "Details", username = "", id = UrlParameter.Optional }, // Parameter defaults + new[] { typeof(Controllers.BlogController).Namespace } + ); + context.MapSubdomainRoute( + "Blog_default_index", // Route name "blog", - "{controller}/{action}/{username}/{id}", // URL with parameters - new { controller = "Blog", action = "Index", username = UrlParameter.Optional, id = UrlParameter.Optional } // Parameter defaults + "", // URL with parameters + new { controller = "Blog", action = "Index" }, // Parameter defaults + new[] { typeof(Controllers.BlogController).Namespace } + ); + context.MapSubdomainRoute( + "Blog_default_detail", // Route name + "blog", + "{username}/{id}", // URL with parameters + new { controller = "Blog", action = "Details", username = "", id = UrlParameter.Optional }, // Parameter defaults + new[] { typeof(Controllers.BlogController).Namespace } ); // Register Bundles BundleTable.Bundles.Add(new ScriptBundle("~/bundles/blog").Include( + "~/Scripts/ocupload/1.1.2/ocupload.js", "~/Areas/Blog/Scripts/Blog.js")); } } diff --git a/Teknik/Areas/Blog/Controllers/BlogController.cs b/Teknik/Areas/Blog/Controllers/BlogController.cs index 5f2e51f..5917752 100644 --- a/Teknik/Areas/Blog/Controllers/BlogController.cs +++ b/Teknik/Areas/Blog/Controllers/BlogController.cs @@ -25,23 +25,26 @@ namespace Teknik.Areas.Blog.Controllers // by default, view the teknik blog Models.Blog blog = db.Blogs.Find(Constants.SERVERBLOGID); - if (blog == null) - { - return HttpNotFound(); - } BlogViewModel model = new BlogViewModel(); - model.BlogId = blog.BlogId; - model.UserId = blog.UserId; - model.User = blog.User; - model.Posts = blog.Posts; + model.BlogId = Constants.SERVERBLOGID; + if (blog != null) + { + model.UserId = blog.UserId; + model.User = blog.User; + model.Posts = blog.Posts; + } return View(model); } // GET: Blogs/Details/5 [AllowAnonymous] - public ActionResult Details(int? id) + public ActionResult Details(string username, int? id) { + if (string.IsNullOrEmpty(username)) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); diff --git a/Teknik/Areas/Contact/ContactAreaRegistration.cs b/Teknik/Areas/Contact/ContactAreaRegistration.cs index 4a6a602..bc7aa70 100644 --- a/Teknik/Areas/Contact/ContactAreaRegistration.cs +++ b/Teknik/Areas/Contact/ContactAreaRegistration.cs @@ -18,14 +18,14 @@ namespace Teknik.Areas.Contact context.MapSubdomainRoute( "Contact_dev", // Route name "dev", - "Contact/{controller}/{action}", // URL with parameters + "Contact", // URL with parameters new { controller = "Contact", action = "Index" }, // Parameter defaults new[] { typeof(Controllers.ContactController).Namespace } ); context.MapSubdomainRoute( "Contact_default", // Route name "contact", - "{controller}/{action}", // URL with parameters + "", // URL with parameters new { controller = "Contact", action = "Index" }, // Parameter defaults new[] { typeof(Controllers.ContactController).Namespace } ); diff --git a/Teknik/Areas/Profile/ProfileAreaRegistration.cs b/Teknik/Areas/Profile/ProfileAreaRegistration.cs index a37c8b5..31b348f 100644 --- a/Teknik/Areas/Profile/ProfileAreaRegistration.cs +++ b/Teknik/Areas/Profile/ProfileAreaRegistration.cs @@ -17,14 +17,14 @@ namespace Teknik.Areas.Profile context.MapSubdomainRoute( "Profile_dev", // Route name "dev", - "Profile/{controller}/{action}", // URL with parameters + "Profile", // URL with parameters new { controller = "Profile", action = "Index" }, // Parameter defaults new[] { typeof(Controllers.ProfileController).Namespace } ); context.MapSubdomainRoute( "Profile_default", // Route name "profile", - "{controller}/{action}", // URL with parameters + "", // URL with parameters new { controller = "Profile", action = "Index" }, // Parameter defaults new[] { typeof(Controllers.ProfileController).Namespace } );