diff --git a/samples/RoutingSample.Web/RouteBuilderExtensions.cs b/samples/RoutingSample.Web/RouteBuilderExtensions.cs index 52c57598fb..e09913bb8c 100644 --- a/samples/RoutingSample.Web/RouteBuilderExtensions.cs +++ b/samples/RoutingSample.Web/RouteBuilderExtensions.cs @@ -1,5 +1,10 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using Microsoft.AspNet.Routing; +using Microsoft.AspNet.Routing.Template; +using Microsoft.Framework.DependencyInjection; namespace RoutingSample.Web { @@ -28,5 +33,28 @@ namespace RoutingSample.Web routeBuilder.Routes.Add(new PrefixRoute(handler, prefix)); return routeBuilder; } + + public static IRouteBuilder MapLocaleRoute( + this IRouteBuilder routeBuilder, + string locale, + string routeTemplate, + object defaults) + { + var defaultsDictionary = new RouteValueDictionary(defaults); + defaultsDictionary.Add("locale", locale); + + var constraintResolver = routeBuilder.ServiceProvider.GetService(); + + var route = new TemplateRoute( + target: routeBuilder.DefaultHandler, + routeTemplate: routeTemplate, + defaults: defaultsDictionary, + constraints: null, + dataTokens: null, + inlineConstraintResolver: constraintResolver); + routeBuilder.Routes.Add(route); + + return routeBuilder; + } } } \ No newline at end of file diff --git a/samples/RoutingSample.Web/Startup.cs b/samples/RoutingSample.Web/Startup.cs index cafb52d9e7..46110ee964 100644 --- a/samples/RoutingSample.Web/Startup.cs +++ b/samples/RoutingSample.Web/Startup.cs @@ -1,12 +1,11 @@ -using System; -using System.Collections.Generic; +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System.Text.RegularExpressions; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing.Constraints; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.OptionsModel; namespace RoutingSample.Web { @@ -56,7 +55,12 @@ namespace RoutingSample.Web new { controller = "Store" }); routeBuilder.AddPrefixRoute("hello/world", endpoint2); + + routeBuilder.MapLocaleRoute("en-US", "store/US/{action}", new { controller = "Store" }); + routeBuilder.MapLocaleRoute("en-GB", "store/UK/{action}", new { controller = "Store" }); + routeBuilder.AddPrefixRoute("", endpoint2); + builder.UseRouter(routeBuilder.Build()); } } diff --git a/samples/RoutingSample.Web/project.json b/samples/RoutingSample.Web/project.json index 3b2dc176fa..c064d98586 100644 --- a/samples/RoutingSample.Web/project.json +++ b/samples/RoutingSample.Web/project.json @@ -1,10 +1,17 @@ { - "dependencies": { - "Microsoft.AspNet.Server.IIS": "1.0.0-*", - "Microsoft.AspNet.Routing" : "1.0.0-*" - }, - "frameworks": { - "aspnet50": {}, - "aspnetcore50": {} - } + "dependencies": { + "Kestrel": "1.0.0-*", + "Microsoft.AspNet.Server.IIS": "1.0.0-*", + "Microsoft.AspNet.Server.WebListener": "1.0.0-*", + "Microsoft.AspNet.Routing": "1.0.0-*" + }, + "commands": { + "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001", + "kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5000" + }, + "frameworks": { + "aspnet50": { }, + "aspnetcore50": { } + }, + "webroot": "wwwroot" }