Skip to content
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.

Commit

Permalink
Implemented LowerCaseRoute for Areas
Browse files Browse the repository at this point in the history
Fix for #5
  • Loading branch information
hanssens committed Mar 11, 2013
1 parent 351701e commit dd65087
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 1 deletion.
1 change: 1 addition & 0 deletions Source/Portality.Common/Portality.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Compile Include="Extensions\RegularExtensions.cs" />
<Compile Include="Helpers\SessionManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Routing\AreaLowerCaseRoute.cs" />
<Compile Include="Routing\LowerCaseRoute.cs" />
</ItemGroup>
<ItemGroup />
Expand Down
111 changes: 111 additions & 0 deletions Source/Portality.Common/Routing/AreaLowerCaseRoute.cs
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;
}
}
}
2 changes: 1 addition & 1 deletion Source/Portality.Common/Routing/LowercaseRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static Route MapLowerCaseRoute(this RouteCollection routes, string name,
/// <param name="constraints">A set of expressions that specify valid values for a URL parameter.</param>
/// <param name="namespaces">An enumerable set of namespaces for the application.</param>
/// <returns></returns>
public static Route MapLowerCaseRoute(this RouteCollection routes, string name, string url, object defaults, string constraints, string[] namespaces)
public static Route MapLowerCaseRoute(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces)
{
Route route = new LowerCaseRoute(url, new MvcRouteHandler())
{
Expand Down

0 comments on commit dd65087

Please sign in to comment.