Localized website, 1 bug: postback event doesn't work
I've almost finished localizing a major website in ASP.NET. I'm using the CurrentUICulture to influence my localization. All goes well, except for the situation where I have a postback event.
If I trigger this postback event, from the page that had it's culture changed, the Postback event uses the OLD CurrentUICulture value. It DOES work correctly if I've visited some other pages in the website first.
I use the correctly localized page to trigger this event, that's why I am sure the localization worked.
Is the postback event on a different thread? Did I miss something? I can't post any code from the project. The only setting I use is Thread.CurrentUICulture withi开发者_运维技巧n a static wrapper class to set and get my localization. The class only contains static properties.
EDIT: We set the currentUIculture in the OnInit of the loading page. We maintain the ui culture by setting it each time from the Session.
Instead of setting the culture in the page OnInit event, override the InitializeCulture event.
Here's an example, in vb, but you get the idea.
Protected Overrides Sub InitializeCulture()
Dim locale As String = Request.QueryString("lc")
If locale IsNot Nothing AndAlso locale = "fr-ca" Then
Me._LocaleID = 3084
End If
Dim culture As New System.Globalization.CultureInfo(Me._LocaleID)
System.Threading.Thread.CurrentThread.CurrentCulture = culture
System.Threading.Thread.CurrentThread.CurrentUICulture = culture
End Sub
I just realized I did not answer this question.
It turns out that a postback (which finally redirects) to another domain, makes the session disappear (obviously, surely good to know anyway).
We've used the httpCookie domain setting to always set all cookies to the main domain, so sessions are shared between the different subdomains (en.website.com and nl.website.com) .
精彩评论