Browse Source

Updated Routing to allow defining the Area.

Modified loading of scripts to move some to end of body.
master
Teknikode 7 years ago
parent
commit
89434ea16e
  1. 42
      Teknik/App_Start/SubdomainRouteExtension.cs
  2. 4
      Teknik/Areas/About/AboutAreaRegistration.cs
  3. 23
      Teknik/Areas/Blog/BlogAreaRegistration.cs
  4. 4
      Teknik/Areas/Contact/ContactAreaRegistration.cs
  5. 15
      Teknik/Areas/Dev/DevAreaRegistration.cs
  6. 12
      Teknik/Areas/Home/HomeAreaRegistration.cs
  7. 1
      Teknik/Areas/Home/Scripts/Home.js
  8. 1
      Teknik/Areas/Home/Views/Home/Index.cshtml
  9. 4
      Teknik/Areas/Privacy/PrivacyAreaRegistration.cs
  10. 1
      Teknik/Teknik.csproj
  11. 10
      Teknik/Views/Shared/_Layout.cshtml

42
Teknik/App_Start/SubdomainRouteExtension.cs

@ -83,5 +83,47 @@ namespace Teknik @@ -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;
}
}
}

4
Teknik/Areas/About/AboutAreaRegistration.cs

@ -18,14 +18,14 @@ namespace Teknik.Areas.About @@ -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 }
);
}

23
Teknik/Areas/Blog/BlogAreaRegistration.cs

@ -14,37 +14,18 @@ namespace Teknik.Areas.Blog @@ -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" }
//);
}
}
}

4
Teknik/Areas/Contact/ContactAreaRegistration.cs

@ -18,14 +18,14 @@ namespace Teknik.Areas.Contact @@ -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 }
);
}

15
Teknik/Areas/Dev/DevAreaRegistration.cs

@ -1,4 +1,5 @@ @@ -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 @@ -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" }
//);
}
}
}

12
Teknik/Areas/Home/HomeAreaRegistration.cs

@ -19,29 +19,23 @@ namespace Teknik.Areas.Home @@ -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" }
//);
}
}
}

1
Teknik/Areas/Home/Scripts/Home.js

@ -0,0 +1 @@ @@ -0,0 +1 @@


1
Teknik/Areas/Home/Views/Home/Index.cshtml

@ -126,7 +126,6 @@ @@ -126,7 +126,6 @@
<ul class="list-group">
@foreach (Post post in Model)
{
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion

4
Teknik/Areas/Privacy/PrivacyAreaRegistration.cs

@ -18,14 +18,14 @@ namespace Teknik.Areas.Privacy @@ -18,14 +18,14 @@ namespace Teknik.Areas.Privacy
"Privacy_dev", // Route name
"dev",
"Privacy/{controller}/{action}", // URL with parameters
new { area = this.AreaName, controller = "Privacy", action = "Index" }, // Parameter defaults
new { controller = "Privacy", action = "Index" }, // Parameter defaults
new[] { typeof(Controllers.PrivacyController).Namespace }
);
context.MapSubdomainRoute(
"Privacy_default", // Route name
"privacy",
"{controller}/{action}", // URL with parameters
new { area = this.AreaName, controller = "Privacy", action = "Index" }, // Parameter defaults
new { controller = "Privacy", action = "Index" }, // Parameter defaults
new[] { typeof(Controllers.PrivacyController).Namespace }
);
}

1
Teknik/Teknik.csproj

@ -166,6 +166,7 @@ @@ -166,6 +166,7 @@
<Compile Include="App_Start\SubdomainRouteExtension.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Areas\Home\Scripts\Home.js" />
<Content Include="Content\CSS\bootstrap-theme.css" />
<Content Include="Content\CSS\bootstrap-theme.min.css" />
<Content Include="Content\CSS\bootstrap.css" />

10
Teknik/Views/Shared/_Layout.cshtml

@ -10,13 +10,8 @@ @@ -10,13 +10,8 @@
<link rel="shortcut icon" href="/Content/Images/favicon.ico" type="image/x-icon" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/markdown")
@Scripts.Render("~/bundles/common")
@RenderSection("scripts", required: false)
</head>
<body data-twttr-rendered="true">
<div id="wrap">
@ -63,5 +58,10 @@ @@ -63,5 +58,10 @@
</script>
<noscript><p><img src="//stats.teknik.io/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
<!-- Load Scripts -->
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/common")
@RenderSection("scripts", required: false)
</body>
</html>

Loading…
Cancel
Save