This repository has been archived by the owner on Mar 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented LowerCaseRoute for Areas
Fix for #5
- Loading branch information
Showing
3 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Web.Mvc; | ||
using System.Web.Routing; | ||
|
||
namespace Portality.Common | ||
{ | ||
/// <summary> | ||
/// Contains extension methods to map routes in Areas to lowercase URLs. | ||
/// </summary> | ||
/// <remarks> | ||
/// Thanks to http://leedumond.com and http://lowercaseroutesmvc.codeplex.com | ||
/// | ||
/// </remarks> | ||
public static class AreaRegistrationContextExtensions | ||
{ | ||
/// <summary> | ||
/// Maps the specified URL route using a lowercase URL and associates it with the area that is specified by the AreaName property. Does not change casing in the querystring, if any. | ||
/// </summary> | ||
/// <param name="context">The context that encapsulates the information that is required in order to register an area within an ASP.NET MVC application.</param> | ||
/// <param name="name">The name of the route.</param> | ||
/// <param name="url">The URL pattern for the route.</param> | ||
/// <returns>A reference to the mapped route.</returns> | ||
public static Route MapRouteLowercase(this AreaRegistrationContext context, string name, string url) | ||
{ | ||
return MapRouteLowercase(context, name, url, null, null, null); | ||
} | ||
|
||
/// <summary> | ||
/// Maps the specified URL route using a lowercase URL and associates it with the area that is specified by the AreaName property, using the specified route default values. Does not change casing in the querystring, if any. | ||
/// </summary> | ||
/// <param name="context">The context that encapsulates the information that is required in order to register an area within an ASP.NET MVC application.</param> | ||
/// <param name="name">The name of the route.</param> | ||
/// <param name="url">The URL pattern for the route.</param> | ||
/// <param name="defaults">An object that contains default route values.</param> | ||
/// <returns>A reference to the mapped route.</returns> | ||
public static Route MapRouteLowercase(this AreaRegistrationContext context, string name, string url, object defaults) | ||
{ | ||
return MapRouteLowercase(context, name, url, defaults, null, null); | ||
} | ||
|
||
/// <summary> | ||
/// Maps the specified URL route using a lowercase URL and associates it with the area that is specified by the AreaName property, using the specified namespaces. Does not change casing in the querystring, if any. | ||
/// </summary> | ||
/// <param name="context">The context that encapsulates the information that is required in order to register an area within an ASP.NET MVC application.</param> | ||
/// <param name="name">The name of the route.</param> | ||
/// <param name="url">The URL pattern for the route.</param> | ||
/// <param name="namespaces">A set of namespaces for the application.</param> | ||
/// <returns>A reference to the mapped route.</returns> | ||
public static Route MapRouteLowercase(this AreaRegistrationContext context, string name, string url, string[] namespaces) | ||
{ | ||
return MapRouteLowercase(context, name, url, null, null, namespaces); | ||
} | ||
|
||
/// <summary> | ||
/// Maps the specified URL route using a lowercase URL and associates it with the area that is specified by the AreaName property, using the specified route default values and constraints. Does not change casing in the querystring, if any. | ||
/// </summary> | ||
/// <param name="context">The context that encapsulates the information that is required in order to register an area within an ASP.NET MVC application.</param> | ||
/// <param name="name">The name of the route.</param> | ||
/// <param name="url">The URL pattern for the route.</param> | ||
/// <param name="defaults">An object that contains default route values.</param> | ||
/// <param name="constraints">A set of expressions that specify valid values for a URL parameter.</param> | ||
/// <returns>A reference to the mapped route.</returns> | ||
public static Route MapRouteLowercase(this AreaRegistrationContext context, string name, string url, object defaults, object constraints) | ||
{ | ||
return MapRouteLowercase(context, name, url, defaults, constraints, null); | ||
} | ||
|
||
/// <summary> | ||
/// Maps the specified URL route using a lowercase URL and associates it with the area that is specified by the AreaName property, using the specified route default values and namespaces. Does not change casing in the querystring, if any. | ||
/// </summary> | ||
/// <param name="context">The context that encapsulates the information that is required in order to register an area within an ASP.NET MVC application.</param> | ||
/// <param name="name">The name of the route.</param> | ||
/// <param name="url">The URL pattern for the route.</param> | ||
/// <param name="defaults">An object that contains default route values.</param> | ||
/// <param name="namespaces">A set of namespaces for the application.</param> | ||
/// <returns>A reference to the mapped route.</returns> | ||
public static Route MapRouteLowercase(this AreaRegistrationContext context, string name, string url, object defaults, string[] namespaces) | ||
{ | ||
return MapRouteLowercase(context, name, url, defaults, null, namespaces); | ||
} | ||
|
||
/// <summary> | ||
/// Maps the specified URL route using a lowercase URL and associates it with the area that is specified by the AreaName property, using the specified route default values, constraints, and namespaces. Does not change casing in the querystring, if any. | ||
/// </summary> | ||
/// <param name="context">The context that encapsulates the information that is required in order to register an area within an ASP.NET MVC application.</param> | ||
/// <param name="name">The name of the route.</param> | ||
/// <param name="url">The URL pattern for the route.</param> | ||
/// <param name="defaults">An object that contains default route values.</param> | ||
/// <param name="constraints">A set of expressions that specify valid values for a URL parameter.</param> | ||
/// <param name="namespaces">A set of namespaces for the application.</param> | ||
/// <returns>A reference to the mapped route.</returns> | ||
public static Route MapRouteLowercase(this AreaRegistrationContext context, string name, string url, object defaults, object constraints, string[] namespaces) | ||
{ | ||
if (namespaces == null && context.Namespaces != null) | ||
{ | ||
namespaces = context.Namespaces.ToArray(); | ||
} | ||
|
||
Route route = context.Routes.MapLowerCaseRoute(name, url, defaults, constraints, namespaces); | ||
|
||
route.DataTokens["area"] = context.AreaName; | ||
route.DataTokens["UseNamespaceFallback"] = (namespaces == null || namespaces.Length == 0); | ||
|
||
return 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