我创建了干净的APS.NET MVC 4项目,我尝试使用this教程进行国际化。
我使用baseController时遇到问题,因为当我运行项目时,基本控制器的功能不会执行。也许我忘了实施一些东西......
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();
}
}
的HomeController
public class HomeController : BaseController
{
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
}
答案 0 :(得分:0)
您可能希望覆盖Initialize
方法而不是ExecuteCore
。
以下是解释和解决方案:ExecuteCore() in base class not fired in MVC 4 beta