在 ASP.NET 网页中哪里可以设置 CurrentUICulture?

发布于 2024-08-24 13:01:48 字数 137 浏览 4 评论 0原文

我正在读一个资源,上面写着:

CurrentUICulture 必须在应用程序启动时设置。

对于 ASP.NET 网页,在哪里适当地设置此属性?

I was reading a resource that said:

CurrentUICulture must be set at the startup of a application.

For an ASP.NET web page, where do I set this property appropriately?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

葬﹪忆之殇 2024-08-31 13:01:48

在网页中,您可以在页面指令中设置 Culture 和 UICulture:

<%@ Page .... Culture="en-US" UICulture="en-US" %>

不必在应用程序启动时设置。

更新:正如 Kristof Claes 在评论中提到的,您可以在 Page_Init 期间在代码中设置它:

System.Threading.Thread.CurrentThread.CurrentCulture =
    new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentUICulture =
    new System.Globalization.CultureInfo("en-US");

In a web page, you can set Culture and UICulture in the page directive:

<%@ Page .... Culture="en-US" UICulture="en-US" %>

It doesn't have to be set at application startup.

Update: And as Kristof Claes mentions in a comment, you can set it in code during Page_Init:

System.Threading.Thread.CurrentThread.CurrentCulture =
    new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentUICulture =
    new System.Globalization.CultureInfo("en-US");
吻安 2024-08-31 13:01:48

网页配置:

<globalization culture="en-US" uiCulture="en" requestEncoding="utf-8" responseEncoding="utf-8" />

Web.config:

<globalization culture="en-US" uiCulture="en" requestEncoding="utf-8" responseEncoding="utf-8" />
执笏见 2024-08-31 13:01:48

您是否尝试过:

  Page.Culture = "your culture";
  Page.UICulture = "your culture";

请参阅 Page.UICulture 属性< /a> 和 Page.Culture 属性 。

Did you try:

  Page.Culture = "your culture";
  Page.UICulture = "your culture";

See Page.UICulture Property and Page.Culture Property on MSDN.

一直在等你来 2024-08-31 13:01:48

我在页面本身上这样做

Protected Overrides Sub InitializeCulture()
    If Not Me.IsPostBack Then
                   Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo(var.Sess.lang)
        Threading.Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.CreateSpecificCulture(Threading.Thread.CurrentThread.CurrentUICulture.Name)
    End If
    MyBase.InitializeCulture()
End Sub

I do this, on the page itself

Protected Overrides Sub InitializeCulture()
    If Not Me.IsPostBack Then
                   Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo(var.Sess.lang)
        Threading.Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.CreateSpecificCulture(Threading.Thread.CurrentThread.CurrentUICulture.Name)
    End If
    MyBase.InitializeCulture()
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文