I have just migrated around 100 ASP.net sites from IIS 6 on Windows Sever 2003 to IIS 7 on Windows 2008. I\'ve just noticed that various pieces of code that use things like
In my case, my application pool was running as my domain user, which had the current culture set to en-GB, and the application worked fine with en-GB date format.
I changed the app pool to be run under Network Service instead and suddenly the DateTime.Parse calls were breaking as the app was now using en-US culture. I saw some SO posts (e.g) about how IIS cultures are user-specific which explains that.
Opening the .NET Globalization of the root element in IIS Manager and setting both Culture and UI Culture to English UK (en-GB) fixed it for me.
These are alternative places where you could search:
I can't find anywhere that's settings the culture to 'en-US'... but something is.
Thread.CurrentThread.CurrentCulture.Name is outputting 'en-US' Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol is outputting '$'
Try looking for the InitializeCulture
method, this method is overridden in ASP.Net pages to set the Culture like:
protected override void InitializeCulture()
{
var hidden = this.Request.Form["hidden"];
var culture = this.Request.Form[hidden];
if (!string.IsNullOrWhiteSpace(culture))
{
this.Culture = culture;
this.UICulture = culture;
}
base.InitializeCulture();
}
Try to look for the following assembly attributes:
[assembly: AssemblyCulture("en-US")]
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
Try to look for the following page directive attributes:
<%@ Page Culture="en-US" UICulture="en-US" Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
Try to look in web.configs:
<globalization uiCulture="en-US" culture="en-US" enableClientBasedCulture="false" />
Try to look for HttpHandlers or HttpModules trying to set the language
Try to look in the web.config hierarchy (at the server, <wwwroot>
means the root folder of your IIS Web Site)
<windir>\Microsoft.NET\Framework\<ver>\Config\Machine.config
<windir>\Microsoft.NET\Framework\<ver>\Config\Web.config
<wwwroot>\Web.config
<wwwroot>\<webapp>\Web.config
<wwwroot>\<webapp>\<dir>\Web.config
If you have multiple servers (web farm), check you are being redirected to the correct server (the one you are checking the configuration), in order to do it you can use the ip of the desired server or configure your host files in your client computer
I've spent hours trying to find a solution for my case. I am working under Win10 (English version), but with Russian regional settings. Nevertheless, I got "en-US" culture in my app, hosted on IIS with ApplicationPoolIdentity. That solved the problem:
IIS -> Application Pools -> Advanced Settings -> Change "Load User Profile" to False
.Net web application is picking up your browser's default culture. For e.g. in FF, default language is set as shown in below image.
So, if you want your site's culture other than the one from browser, in page's InitializeCulture method (Create a BasePage and keep below code here and inherit existing pages from this BasePage).
protected override void InitializeCulture()
{
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-GB");
System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
base.InitializeCulture();
}
}
I had this problem too, but I solved it. You must set the following values:
CultureInfo.DefaultThreadCurrentCulture = "en-GB";
CultureInfo.DefaultThreadCurrentUICulture = "en-GB";
Just to help someone gets the same problem....
After tried change IIS Culture, set globalization and so far unsecessfully, i did it in Global.asax:
void Application_BeginRequest(Object sender, EventArgs e)
{
System.Globalization.CultureInfo newCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
newCulture.DateTimeFormat.DateSeparator = "/";
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture;
}