Browse Source

Modified routing to better match real URL.

tags/2.0.3
Teknikode 4 years ago
parent
commit
1d8c4fba34

+ 24
- 7
Teknik/Areas/Blog/BlogAreaRegistration.cs View File

@@ -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",
"", // URL with parameters
new { controller = "Blog", action = "Index" }, // Parameter defaults
new[] { typeof(Controllers.BlogController).Namespace }
);
context.MapSubdomainRoute(
"Blog_default_detail", // Route name
"blog",
"{controller}/{action}/{username}/{id}", // URL with parameters
new { controller = "Blog", action = "Index", username = UrlParameter.Optional, id = UrlParameter.Optional } // Parameter defaults
"{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"));
}
}

+ 11
- 8
Teknik/Areas/Blog/Controllers/BlogController.cs View File

@@ -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)
BlogViewModel model = new BlogViewModel();
model.BlogId = Constants.SERVERBLOGID;
if (blog != null)
{
return HttpNotFound();
model.UserId = blog.UserId;
model.User = blog.User;
model.Posts = blog.Posts;
}
BlogViewModel model = new BlogViewModel();
model.BlogId = blog.BlogId;
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);

+ 2
- 2
Teknik/Areas/Contact/ContactAreaRegistration.cs View File

@@ -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 }
);

+ 2
- 2
Teknik/Areas/Profile/ProfileAreaRegistration.cs View File

@@ -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 }
);

Loading…
Cancel
Save