问题描述:

I have setup the cultures for my views and changing the culture in a controller but I can't seem to find how to know what culture I'm currently using in a controller, I'm looking for something like:

public class HomeController : Controller {

public async Task<IActionResult> Index()

{

// Something like the next line

var requestCulture = GetRequestedCulture()

return View();

}

}

Thanks for all your help

网友答案:

The answer was on the Request Object, here's the code:

public async Task<IActionResult> Index() {
    // Retrieves the requested culture
    var rqf = Request.HttpContext.Features.Get<IRequestCultureFeature>();
    // Culture contains the information of the requested culture
    var culture = rqf.RequestCulture.Culture;
    return View();
}
相关阅读:
Top