I would greatly appreciate your help in solving the following. I have setup my site to add the culture indicator into the route using the methods described in Alex Adamyan's blog Addition to ASP.NET MVC Localization - Using routing. It works great with one exception. My site uses a WebApi controller and when I make a call to an action called Upload the request is Aborted with no other errors. The issue is that in the link request the Localization route preappend the request with the culture code so that the url looks like this:
http://mysite/en/api/upload/021a6305-0e40-4a4a-a129-43c611aac371
The call to the api should not have the culture code in it and should look like this:
http://mysite/api/upload/021a6305-0e40-4a4a-a129-43c611aac371
I have tried to eliminate this by adding a route map and using the SingleCultureRouteHandeler described in the article.
Route Map Used
routes.MapRoute(
"WebApi",
"api/{controller}/{id}",
new { controller = "Upload", id = UrlParameter.Optional }
).RouteHandler = new SingleCultureMvcRouteHandler();
I have tried the above route with and without the controller with no success.
Route Config (Just in case in missing something).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Infrastructure.Routing;
namespace MySite.MVC
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"WebApi",
"api/{controller}/{id}",
new { id = UrlParameter.Optional }
).RouteHandler = new SingleCultureMvcRouteHandler();
foreach (Route r in routes)
{
if (!(r.RouteHandler is SingleCultureMvcRouteHandler))
{
r.RouteHandler = new MultiCultureMvcRouteHandler();
r.Url = "{culture}/" + r.Url;
//Adding default culture
if (r.Defaults == null)
{
r.Defaults = new RouteValueDictionary();
}
r.Defaults.Add("culture", Culture.en.ToString());
//Adding constraint for culture param
if (r.Constraints == null)
{
r.Constraints = new RouteValueDictionary();
}
r.Constraints.Add("culture", new CultureConstraint(Culture.en.ToString(), Culture.es.ToString(), Culture.mn.ToString()));
}
}
}
}
}
Thanks for your help in advance.