This is my route:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "defaultWithCulture",
template: "{culture=fa-IR}/{controller}/{action=Index}/{id?}");
});
but localization works when I use the link:
http://localhost:1776/fa-IR/Home/About?culture=fa-ir
but not when
http://localhost:1776/fa-IR/Home/About
why doesn't the culture in the route apply?
As far as I know, asp.net core has following RequestCultureProviders, in order. First non-null will be used.
and you need to add RouteDataRequestCultureProvider to support culture from route data.
taking an example from here:
SSA's answer didn't solve my problem but gave me a big clue, and finally I got it to work.
The thing to do is:
So we must change the order of them and add the Routing to be the first:
2- When RouteDataRequestCultureProvider Task executed, still the RoutingData is null and is not given a value yet, so it will always return null, so I changed it like Below to use the
Url.Path
instead of RoutingData: