我有一个包含三个域 .com、.de 和 .it 的网站
每个域都需要默认为该国的当地语言/文化。我创建了一个基本页面并添加了一个 InitializeCulture
Protected Overrides Sub InitializeCulture()
Dim url As System.Uri = Request.Url
Dim hostname As String = url.Host.ToString()
Dim SelectedLanguage As String
If HttpContext.Current.Profile("PreferredCulture").ToString Is Nothing Then
Select Case hostname
Case "www.domain.de"
SelectedLanguage = "de"
Thread.CurrentThread.CurrentUICulture = New CultureInfo(SelectedLanguage)
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(SelectedLanguage)
Case "www.domain.it"
SelectedLanguage = "it"
Thread.CurrentThread.CurrentUICulture = New CultureInfo(SelectedLanguage)
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(SelectedLanguage)
Case Else
SelectedLanguage = "en"
Thread.CurrentThread.CurrentUICulture = New CultureInfo(SelectedLanguage)
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(SelectedLanguage)
End Select
End If
End Sub
这可以。现在出现问题是因为我们还想要主页上的三个语言选择按钮,以便用户可以覆盖域语言。
所以在我的 Default.asp.vb 上,我们有三个像这样的按钮事件......
Protected Sub langEnglish_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles langEnglish.Click
Dim SelectedLanguage As String = "en"
'Save selected user language in profile'
HttpContext.Current.Profile.SetPropertyValue("PreferredCulture", SelectedLanguage)
'Force re-initialization of the page to fire InitializeCulture()'
Context.Server.Transfer(Context.Request.Path)
End Sub
但当然,InitializeCulture 会覆盖所做的任何按钮选择。InitialCulture 有什么方法可以检查是否发生了按钮单击,如果是,则跳过该例程?
任何建议将不胜感激,谢谢。