0

我创建了干净的 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();
        }
}
4

1 回答 1

0

您可能想要改写该Initialize方法ExecuteCore

这是一个解释和解决方案:ExecuteCore() in base class not fire in MVC 4 beta

于 2013-08-05T17:50:47.087 回答