我有一个基类,该类实现了受保护的重写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")
返回的值是美国。
从不调用覆盖的方法,并且测试页中的txtCulture.Text = Thread.CurrentThread.CurrentCulture.Name
始终返回en-GB!
答案 0 :(得分:1)
您是否从BasePage
继承了System.Web.UI.Page
,我转载了它
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)
{
}
}
}