我的工作是在MVC应用程序和WebAPI .both应用程序中分别托管。
下面的区域性代码是在MVC应用程序的Global.asax中提到的
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
string langCode = "";
try
{
langCode = HttpContext.Current.Request.Cookies["es-mx].Value;
}
catch (Exception)
{
langCode = "en-US";
}
CultureInfo ci = new CultureInfo(langCode);
Thread.CurrentThread.CurrentUICulture = (ci);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
}
我的mvc应用程序知道当前的culture.my GET/POST请求从MVC控制器发送到web。
public JsonResult callWebApiAdmin(EmpViewModel objEmpModel)
{
object resultView = null;
try
{
string url = webAPIUrl + "EmpAPI/callWebApiAdmin";
resultView = UtilityHelper.SaveData(url, objEmpModel);
}
catch (Exception ex)
{
}
return Json(resultView, JsonRequestBehavior.AllowGet);
}
但是webAPI如何根据MVC应用程序的当前文化知道mvc调用哪个文化,webAPI返回日期、时间和数字格式的Application.so。
发布于 2015-05-28 16:20:39
您还可以在Web API中检查cookies。您可以在Web API操作筛选器中实现它,如果您使用的是OWIN,则可以在自定义中间件组件中实现,以便为所有请求自动完成此操作。
如果没有,您应该将区域性存储在客户端,并将其作为参数发送给服务器端的所有请求。
但是,如果您使用的是Web API,则很可能会根据API返回的值更改客户端中的DOM元素。在这种情况下,您可以从Web返回原始值,并在客户端对它们进行格式化,例如使用moment.js表示日期。
https://stackoverflow.com/questions/30499509
复制相似问题