我创建了干净的 APS.NET MVC 4 项目,并尝试使用本教程进行国际化。
我在使用 baseController 时遇到问题,因为当我运行项目时,基本控制器的功能没有执行。也许我忘记实现一些东西......
基本控制器
public class BaseController : Controller
{
protected override void ExecuteCore()
{
string cultureName = null;
//Attempt to read the culture cookie from Request
HttpCookie cultureCookie = Request.Cookies["_culture"];
if (cultureCookie != null)
cultureName = cultureCookie.Value;
else
cultureName = Request.UserLanguages[0]; //obtain it from HTTP
//Validation culture name
cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe
//Modify current thread's cultures
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
base.ExecuteCore();
}
}
家庭控制器
public class HomeController : BaseController
{
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
}