ASP.NET - Localization
Modulo per l'impostazione della culture

Di seguito riporto un HttpModule che consente di impostare la culture del thread corrente,
consentendo così di localizzare data e ora, currency etc...:

   1:  /// <summary>
   2:  /// Set current thread culture based on 
   3:  /// browser settings. If client send a request
   4:  /// using a not supported culture the English culture
   5:  /// is selected.
   6:  /// </summary>
   7:  public class CultureModule : IHttpModule
   8:  {
   9:   
  10:      #region IHttpModule Members
  11:   
  12:      void IHttpModule.Dispose() { }
  13:   
  14:      void IHttpModule.Init(HttpApplication context)
  15:      {
  16:          context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
  17:      }
  18:   
  19:      void context_PreRequestHandlerExecute(object sender, EventArgs e)
  20:      {
  21:   
  22:          HttpContext context = HttpContext.Current;
  23:          const string defaultLanguage = "en";
  24:          string culture = defaultLanguage;
  25:          if (context.Request.UserLanguages.Length > 0)
  26:              culture = context.Request.UserLanguages[0];
  27:   
  28:          CultureInfo ci;
  29:          try
  30:          {
  31:              ci = CultureInfo.CreateSpecificCulture(culture);
  32:          }
  33:          catch
  34:          {
  35:              ci = CultureInfo.CreateSpecificCulture(defaultLanguage);
  36:          }
  37:   
  38:          Thread.CurrentThread.CurrentCulture = ci;
  39:          Thread.CurrentThread.CurrentUICulture = ci;
  40:      }
  41:   
  42:      #endregion
  43:  }


Matteo Migliore.