选项1
在 ASP.NET 页面 (ASPX) 中,您需要重写该InitializeCulture
方法:
protected override void InitializeCulture()
{
this.UICulture = "";
this.Culture = "";
}
选项 2
在页面的标记中:
<%@ Page UICulture="" Culture=""
选项 3
在 web.config
<globalization culture="" uiCulture="" enableClientBasedCulture="true" />
选项 4
使用HttpModule
(此示例使用 ASP.NET 配置文件来获取语言,您可以更改以从不同来源获取语言)
public class LocalizationModule : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += context_PreRequestHandlerExecute;
}
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
var application = sender as HttpApplication;
var context = application.Context;
var handler = context.Handler;
var profile = context.Profile as CustomProfile;
if (handler != null)
{
var page = handler as Page;
if (page != null)
{
if (profile != null)
{
if (!string.IsNullOrEmpty(profile.Language))
{
page.UICulture = profile.Language;
page.Culture = profile.Language;
}
}
}
}
}
}
然后你只需要在 web.config 文件中配置它:
<httpModules>
<add name="Localization" type="Msts.Topics.Chapter06___Globalization_and_Accessibility.Lesson01___Globalization_and_Localization.LocalizationModule" />
</httpModules>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<add name="Localization" type="Msts.Topics.Chapter06___Globalization_and_Accessibility.Lesson01___Globalization_and_Localization.LocalizationModule" />
</modules>
</system.webServer>