Get browser language in .AspNetCore2.0?

后端 未结 4 1167
渐次进展
渐次进展 2021-02-19 08:16

I am trying to get the default language from the browser and I use the following code to get it:

var languages = HttpContext.Request.UserLanguages;
4条回答
  •  情深已故
    2021-02-19 08:52

    You can get the browser language from the Request Headers

    Write on your controller:

    //For example --> browserLang = 'en-US'
    var browserLang= Request.Headers["Accept-Language"].ToString().Split(";").FirstOrDefault()?.Split(",").FirstOrDefault();
    

提交回复
热议问题