【发布时间】:2015-05-28 07:08:46
【问题描述】:
我在 MVC 应用程序和 WebAPI 中工作。这两个应用程序分别托管。
在 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 应用程序了解当前的文化。我的 GET/POST 请求从 MVC 控制器转到 Web API。
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 应用程序的文化调用。以便 webAPI 根据 mvc 应用程序当前文化返回日期时间和数字格式。
【问题讨论】:
标签: asp.net-mvc asp.net-web-api globalization