Search code examples
c#asp.net-mvcdate-formatglobalizationaspnetboilerplate

Asp net boilerplate - date format dd/mm/yy


In using Asp net boilerplate framework (abp 1.5.1) in my project. I want to use date format dd/mm/yyyy in my project. For this I've tried in web.config

<globalization culture="en-GB" uiCulture="en-GB" />

In the global.asax.cs I've added following code

protected override void Application_BeginRequest(object sender, EventArgs e)
{
    base.Application_BeginRequest(sender, e);
    System.Globalization.CultureInfo customCulture = new System.Globalization.CultureInfo("en-GB", true);
    System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
    System.Threading.Thread.CurrentThread.CurrentUICulture = customCulture;
}

Solution

  • For the Aspnet Boilerplate Framework (v1.5.1), I don't need to modify the web.config. Just write the following code in the global.asax.cs:

    protected virtual void Application_PostAuthenticateRequest(object sender, EventArgs e)
    {
        CultureInfo customCulture = new CultureInfo("en-GB", true);
        Thread.CurrentThread.CurrentCulture = customCulture;
        Thread.CurrentThread.CurrentUICulture = customCulture;
    }
    

    The problem was I wrote that code in Application_BeginRequest method. But I had to write that code in the Application_PostAuthenticateRequest method.