Example #1
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            // Web API configuration and services

            // Web API routes
            // config.MapHttpAttributeRoutes();

            var defaultCulture = CultureInfo.GetCultureInfo("en-US");

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // Use lowercase urls for consistency
            routes.LowercaseUrls = true;

            // Map routes to Kentico HTTP handlers first as some Kentico URLs might be matched by the default ASP.NET MVC route resulting in displaying pages without images
            routes.Kentico().MapRoutes();

            // Maps the Not found route (the route needs to be registered separately to allow cultureless url)
            routes.MapRoute(
                "NotFound",
                "notfound",
                new { controller = "NotFound", action = "Index" }
                );

            // Web API routes
            routes.MapHttpAttributeRoutes();

            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }
        public static void RegisterRoutes(RouteCollection routes)
        {
            // See http://github.com/mccalltd/AttributeRouting/wiki for more options.
            // To debug routes locally using the built in ASP.NET development server, go to /routes.axd

            // ASP.NET Web API
            routes.MapHttpAttributeRoutes();
        }
        public static void RegisterRoutes(RouteCollection routes)
        {
            // See http://github.com/mccalltd/AttributeRouting/wiki for more options.
            // To debug routes locally using the built in ASP.NET development server, go to /routes.axd

            // ASP.NET Web API
            routes.MapHttpAttributeRoutes();
        }
Example #4
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // See http://github.com/mccalltd/AttributeRouting/wiki for more options.
            // To debug routes locally using the built in ASP.NET development server, go to /routes.axd
            routes.MapAttributeRoutes();

            routes.MapHttpAttributeRoutes();
        }
        public static void Register(RouteCollection routes)
        {
            routes.Clear();
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapHttpAttributeRoutes(c =>
                                              {
                                                  c.ScanAssembly(Assembly.GetExecutingAssembly());
                                                  c.AutoGenerateRouteNames = true;
                                                  c.UseLowercaseRoutes = true;
                                                  c.AppendTrailingSlash = true;
                                                  c.RouteNameBuilder = specification =>
                                                                       "api_" +
                                                                       specification.ControllerName.
                                                                           ToLowerInvariant() +
                                                                       "_" +
                                                                       specification.ActionName.
                                                                           ToLowerInvariant();
                                              });
            routes.MapAttributeRoutes(c =>
                                          {
                                              c.ScanAssembly(Assembly.GetExecutingAssembly());
                                              c.AutoGenerateRouteNames = true;
                                              c.UseLowercaseRoutes = true;
                                              c.AppendTrailingSlash = true;
                                              c.RouteNameBuilder = specification =>
                                                                   specification.ControllerName.
                                                                       ToLowerInvariant() +
                                                                   "_" +
                                                                   specification.ActionName.ToLowerInvariant();
                                          });

            routes.MapRouteLowercase(
                name: "default",
                url: "{controller}/{action}/{id}",
                defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional}
                );

            routes.MapRouteLowercase(
                "homepage",
                "",
                new {controller = "Home", action = "Index"}
                );
        }
Example #6
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            var translationProvider = new FluentTranslationProvider();
            var routePrefixDict     = new Dictionary <string, string>
            {
                { "es", "es-RoutePrefixUrl" },
                { "fr", "fr-RoutePrefixUrl" },
            };
            var indexRouteUrlDict = new Dictionary <string, string>
            {
                { "es", "es-RouteUrl" },
                { "fr", "fr-RouteUrl" },
            };

            // MVC localized controller
            translationProvider.AddTranslations()
            .ForController <Controllers.LocalizationController>()
            .AreaUrl(new Dictionary <string, string>
            {
                { "es", "{culture}/es-AreaUrl" },
                { "fr", "{culture}/fr-AreaUrl" },
            })
            .RoutePrefixUrl(routePrefixDict)
            .RouteUrl(c => c.Index(), indexRouteUrlDict);

            // Web API localized controller
            translationProvider.AddTranslations()
            .ForController <Areas.Api.Controllers.LocalizationController>()
            .AreaUrl(new Dictionary <string, string>
            {
                { "es", "api/{culture}/es-AreaUrl" },
                { "fr", "api/{culture}/fr-AreaUrl" },
            })
            .RoutePrefixUrl(routePrefixDict)
            .RouteUrl(c => c.GetLocalized(), indexRouteUrlDict);

            // Web API (WebHost)
            routes.MapHttpAttributeRoutes(config =>
            {
                config.ScanAssemblyOf <PlainController>();
                config.AddDefaultRouteConstraint(@"[Ii]d$", new RegexRouteConstraint(@"^\d+$"));
                config.UseRouteHandler(() => new HttpCultureAwareRoutingHandler());
                config.AddTranslationProvider(translationProvider);
                config.UseLowercaseRoutes = true;
                config.InheritActionsFromBaseController = true;
            });

            routes.MapAttributeRoutes(config =>
            {
                config.ScanAssemblyOf <HomeController>();
                config.AddDefaultRouteConstraint(@"[Ii]d$", new RegexRouteConstraint(@"^\d+$"));
                config.AddTranslationProvider(translationProvider);
                config.UseRouteHandler(() => new CultureAwareRouteHandler());
                config.UseLowercaseRoutes = true;
                config.InheritActionsFromBaseController = true;
            });

            routes.MapRoute("CatchAll",
                            "{*path}",
                            new { controller = "home", action = "filenotfound" },
                            new[] { typeof(HomeController).Namespace });
        }