我有一个项目 mvc 4 c# 我正在使用资源文件进行本地化。我有行动改变文化
public ActionResult ChangeCulture(string lang, string returnUrl)
{
if (lang.Equals("he-IL"))
{
CultureInfo ci = new CultureInfo(lang);
ci.DateTimeFormat.ShortDatePattern = "dd/MM/yy";
ci.DateTimeFormat.LongDatePattern = "dd/MM/yy";
ci.DateTimeFormat.LongTimePattern = "HH:mm";
ci.DateTimeFormat.ShortTimePattern = "HH:mm";
ci = new CultureInfo(lang);
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
}
else if (lang.Equals("en-US"))
{
CultureInfo ci = new CultureInfo(lang);
ci = new CultureInfo(lang);
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
}
else
{
return new HttpStatusCodeResult(404);
}
return Redirect(returnUrl);
}
在视图中,我从资源中获取文本并且效果很好。
<div>@(ViewRes.GlobalResource.Hello)</div>
但是当我从 SignalR 集线器返回文本时,它总是相同的语言。为什么?