我的页面中有以下代码,
Dim ci As New CultureInfo("en-US")
Thread.CurrentThread.CurrentCulture = ci
Thread.CurrentThread.CurrentUICulture = ci
MyBase.InitializeCulture()
在页面上这很好用。当我从下拉列表中改变文化时,它会设置不同的文化。问题是,这适用于单页。一旦我转到下一页,文化就会设置为默认值。我不想在每个页面上写上面的代码。
如果有人可以帮忙吗?
答案 0 :(得分:1)
只需在global.asax
中的AcquireRequestState
方法中设置文化
当ASP.NET获取与当前请求关联的当前状态(例如,会话状态)时发生。
Sub Application_AcquireRequestState(ByVal sender As Object, ByVal e As EventArgs)
If Not HttpContext.Current Is Nothing AndAlso Not HttpContext.Current.Session Is Nothing Then
If (Session("culture") IsNot Nothing) Then
Dim ci As New System.Globalization.CultureInfo(Session("culture").ToString())
System.Threading.Thread.CurrentThread.CurrentCulture = ci
System.Threading.Thread.CurrentThread.CurrentUICulture = ci
End If
End If
End Sub