【问题标题】:Http Module to change culture has no effectHttp Module 改变文化没有效果
【发布时间】:2012-03-07 07:33:14
【问题描述】:

我在我的项目中使用CultureModule.cs 根据我的变量值设置文化信息。这是一个例子

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"/>

目前我的变量是英式格式,但是日期是以美式格式执行的。

我的问题是,我是否以正确的方式进行操作,或者仍然缺少某些东西。

【问题讨论】:

    标签: c# asp.net cultureinfo


    【解决方案1】:

    格式取决于Thread.CurrentUICulture

    所以你会这样做:

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

    how to set the Culture in asp.net on msdn

    【讨论】:

    • ,,,, 我尝试这样做,但我尝试比较的日期仍在以美国格式进行比较,,, 我正在使用比较验证器来比较它们
    • @freebird 我希望您注意到代码中显示的是 CurrentUICulture。你能更好地描述出了什么问题吗?它以错误的格式显示?还是实际比较不起作用。
    • ,,,, 基于我的 httpmodule ,,,culture 设置为 en-GB 或 en_US ,,, 它们基于 Global.gDateFormat 的值设置...
    • 好的,但是什么不起作用?日期是否显示错误或比较不起作用当您以正确的格式输入日期时
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-12
    • 1970-01-01
    • 2013-09-07
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    相关资源
    最近更新 更多