2012-03-07 10 views
0

私のプロジェクトでは、私の変数の値に基づいて文化情報を設定するために私はCultureModule.csを使用しています。ここでの例では、次のように私はweb.configファイルでそれを設定しています。この後文化を変更するHttpモジュールは効果がありません

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Globalization; 

namespace CwizBankApp 
{ 
    public class CultureModule:IHttpModule 
    { 
     public void Dispose() 
     { 
     } 
     public void Init(HttpApplication context) 
     { 
      context.PostAuthenticateRequest += 
          new EventHandler(context_PostAuthenticateRequest); 
     } 
     void context_PostAuthenticateRequest(object sender, EventArgs e) 
     { 

      CultureInfo currentCulture; 
      if (Global.gDateFormat.Trim() == "British") 
      { 
       currentCulture = new System.Globalization.CultureInfo("en-GB"); 
      } 
      else 
      { 
       currentCulture = new System.Globalization.CultureInfo("en-US"); 
      } 


      System.Threading.Thread.CurrentThread.CurrentCulture 
                  = currentCulture; 
     } 
    } 
} 

です:

<add name="CultureModule" 
       type="CwizBankApp.HttpModules.CultureModule,CwizBankApp"/> 

現在、私の変数は、日付が米国の形式で行われているが、英国のフォーマットです。

私の質問は正しい方法でやっているのか、まだ何かが欠落しています。

答えて

2

フォーマットはThread.CurrentUICultureに依存します。

だから、あなたはどうなる:

System.Threading.Thread.CurrentThread.CurrentUICulture = currentCulture; 

how to set the Culture in asp.net on msdnを参照してください。

+0

,,,私はそれをやってみましたが、私は比較しようとしている日付がまだ米国のフォーマットで比較されています,,,私はそれらをcomapreに比較バリデータを使用しています – freebird

+0

@freebirdあなたの比較コードを投稿できますか? – gideon

+0

freebird

関連する問題