Routing and Localizing ASP.NET MVC Attributes

Attempting to configure attribute routing combined with culture in a URI.

I want to configure routes this way:

www.domain.com/{culture} / {controller} / {action} ... and some parameters as well as www.domain.com/{controller} / {action} ... (the same, but without the specified culture)

The problem is that I do not know how to identify the default culture for the user (browser) in this way.

As I know, I have only two options when using attribute routing:

  • optional parameter {culture?}
  • default value {culture = en}

but both of them are not enough to get a custom culture when it is not specified directly in the URI

+4
source share
1 answer

HTTP- Accept-Language, URL- .

Request.UserLanguages[], , , , , , :

if (HttpContext.Current != null && HttpContext.Current.Request.UserLanguages != null && HttpContext.Request.UserLanguages.Any())
{
    var culture = CultureInfo.GetCultureInfo(Request.UserLanguages[0]);   
}

W3C 14.4

UPDATE

.

0

All Articles