Created
December 2, 2015 13:26
-
-
Save sebnilsson/77961384bc473c873826 to your computer and use it in GitHub Desktop.
Manually map an area-specific route
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class RouteCollectionAreasExtensions | |
{ | |
public static Route MapAreaRoute( | |
this RouteCollection routes, | |
string areaName, | |
string routeName, | |
string url, | |
object defaults = null, | |
object constraints = null, | |
string[] namespaces = null) | |
{ | |
// Null-checks for: routes, areaName, routeName, url | |
var route = routes.MapRoute( | |
routeName, | |
url, | |
defaults: defaults, | |
constraints: constraints, | |
namespaces: namespaces); | |
route.Defaults["area"] = areaName; | |
route.DataTokens["area"] = areaName; | |
if (namespaces != null && namespaces.Any()) | |
{ | |
route.DataTokens["UseNamespaceFallback"] = false; | |
} | |
return route; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment