Dresel / RouteLocalization

RouteLocalization is an MVC and Web API package that allows localization of your attribute routes.
MIT License
67 stars 13 forks source link

Force route to have culture value in URL #70

Closed mdmoura closed 7 years ago

mdmoura commented 7 years ago

I have the following route:

  public class CampaignController : Controller {
    [HttpGet("{name}")]
    public async Task<IActionResult> Show(String name) {
    }
 }

So the URL is something like: /some-campaign-name

This URL should return Page Not Found and I would like to force the culture into the URL so:

/en/campaign/some-campaign-name

or 

/pt/campanha/some-campaign-name

I used the following:

.AddRouteLocalization(x => {          
   x.UseCulture("en")
     .WhereController(nameof(CampaignController))
     .WhereAction(nameof(CampaignController.Show))
     .TranslateAction("campaign/{name}");          

  x.UseCulture("pt")
    .WhereController(nameof(CampaignController))
    .WhereAction(nameof(CampaignController.Show))
    .TranslateAction("campanha/{name}")
    .RemoveOriginalRoutes();          

I am able to access

/en/campaign/some-campaign-name (Expected)

But not able to access

/some-campaign-name (Expected)
/pt/campanha/some-campaign-name (NOT EXPECTED)

Why is the Protuguese version not working? Any idea?

mdmoura commented 7 years ago

The problem was in my code ... Solved