mccalltd / AttributeRouting

Define your routes using attributes on actions in ASP.NET MVC and Web API.
http://mccalltd.github.io/AttributeRouting/
MIT License
416 stars 89 forks source link

Custom Route Translation and UiCulture Constraint #290

Open BoasE opened 10 years ago

BoasE commented 10 years ago

I translate routes with a custom translator. But a user can now call both. The origin (nontranslated) url and the translated url .

I want the user to only call the translated ur. I expected the ConstrainTranslatedRoutesByCurrentUICulture todo so but it doesn't This only prevents the user to call other localizations but does not prevent the user to to call the untranslated url.

Am I doing something wrong or is this an expected behavior ?

        public override string GetTranslation(string key, string cultureName)
        {
            if (key == "url_users")
            {
                return "foo";
            }

            return null;
        }

i've a controller like this:

   public class HomeController : Controller
    {
        [GET("users", TranslationKey = "url_users")]

        public ActionResult Users()
        {
            return View();
        }
    }

and my configuration method looks like that:

         var translator = new AttributeRoutingTranslator();
            routes.MapAttributeRoutes(config =>
            {
                config.AddRoutesFromAssembly(typeof(AttributeRoutingConfig).Assembly);
                config.AddTranslationProvider(translator);
                config.ConstrainTranslatedRoutesByCurrentUICulture = true;
            });

        }