Asp.net
在控制器 asp.net-core 中獲取目前區域性
我已經為我的視圖設置了文化並更改了控制器中的文化,但我似乎無法找到如何知道我目前在控制器中使用的文化,我正在尋找類似的東西:
public class HomeController : Controller { public async Task<IActionResult> Index() { // Something like the next line var requestCulture = GetRequestedCulture() return View(); } }
答案在請求對像上,程式碼如下:
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(); }