为什么不调用 InitializeCulture

Why is InitializeCulture not being called

我有一个基本页面 class 实现了 protected override void InitializeCulture() 但是在页面呈现过程中从未调用它?

我已将以下代码添加到我的基本页面

        protected override void InitializeCulture()
        {
            var cultureCode = ConfigManager.GetConfig("System:CultureCode") ?? "en-GB";
            var cultureInfo = CultureInfo.CreateSpecificCulture(cultureCode);
            Thread.CurrentThread.CurrentCulture = cultureInfo;
            Thread.CurrentThread.CurrentUICulture = cultureInfo;
        }

ConfigManager.GetConfig("System:CultureCode") 返回的值为 en-US。

永远不会调用覆盖的方法,我的测试页中的 txtCulture.Text = Thread.CurrentThread.CurrentCulture.Name 总是 returns en-GB!

你是从System.Web.UI.Page继承了BasePage吗,我转载成功了

public class BasePage : System.Web.UI.Page
    {
        protected override void InitializeCulture()
        {
            var cultureCode = ConfigManager.GetConfig("System:CultureCode") ?? "en-GB";
            var cultureInfo = CultureInfo.CreateSpecificCulture(cultureCode);
            Thread.CurrentThread.CurrentCulture = cultureInfo;
            Thread.CurrentThread.CurrentUICulture = cultureInfo;
        }
    }

默认页面

public partial class _Default : BasePage
{
       protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {                   
            } 
        }
}