2012-03-07 19 views
0

我在我的項目中使用CultureModule.cs來根據變量的值設置文化信息。這裏是例子改變文化的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; 
     } 
    } 
} 

這個我在web.config中配置它,具體如下:

<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 2012-03-07 07:42:50

+0

@freebird您可以發佈您比較代碼? – gideon 2012-03-07 07:43:17

+0

freebird 2012-03-07 07:44:25