Get the current culture in a controller asp.net-core

前端 未结 5 913
隐瞒了意图╮
隐瞒了意图╮ 2021-02-05 01:26

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 loo

5条回答
  •  日久生厌
    2021-02-05 01:57

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

    public async Task Index() {
        // Retrieves the requested culture
        var rqf = Request.HttpContext.Features.Get();
        // Culture contains the information of the requested culture
        var culture = rqf.RequestCulture.Culture;
        return View();
    }
    

提交回复
热议问题