22

To clarify the title.

When you create an application pool in IIS you give it a name. You can then set the identity to ApplicationPoolIdentiy.

Windows then creates this magic user you can't see. Say the app pool name is MyTestAppPool so you would end up with a user called MyTestAppPool (IIS AppPool\MyTestAppPool)

When this happens Windows uses the servers current locale. Let's say it was US at the time.

Then later you change it to UK. While there is a copy this doesn't copy to these magic users I've found. So your server is set to UK while your MyTestAppPool is set to US.

So when a website runs and you need to say format something to currency in the correct locale you end up with US currency because of the AppPool instead of UK currency.

Is there a way to change the AppPool user's locale?

The only way I have found is to delete the app pool and recreate it again after you've set the servers locale to what you want. What if I don't want to do that.

What if I need to have multiple websites running in different locales how would I set the AppPoolIdentity user locale to each of these without having to change the server to what I want before I create the apppool?

Chris Ward
  • 771
  • 1
  • 9
  • 23
  • Can't you change that with the registry in HKEY_USERS\\Control Panel\International as explained here http://stackoverflow.com/questions/1202515/where-does-asp-and-iis-6-0-get-its-date-format ? – Simon Mourier Dec 03 '16 at 06:44
  • *1)* Regional settings belong to a user. What do you mean when you say *the customer has requested it use the system's local*? *2)* What's the problem with creating some local users on server to use for application pool identity? – Reza Aghaei Dec 03 '16 at 08:50
  • This does not solve the problem, however, if you set the CurrentThread.Culture="en-GB" when your application starts and for each request then localized routines will run in that locale. – Ross Bush Dec 06 '16 at 15:40

6 Answers6

14

When you create and use an App Pool Identity, a "user" is created and there is a folder at C:\Users\AppPoolName.

In C:\Windows\System32\inetsrv\config\applicationHost.config there is an element which on my machine looks like this:

<applicationPoolDefaults managedRuntimeVersion="v4.0">
  <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="false" />
</applicationPoolDefaults>

The combination of these two settings determines the environment (and thus locale) settings that app pool identity runs as.

You should be able to figure out the unique Id by checking in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\hivelist for the user that loads the ..\Users\AppPoolName\NTUSER.DAT and then match it up with the settings in HKEY_USERS\UnqiueId\ControlPanel\International\Locale settings.

It may just be simpler to set setProfileEnvironment="false" unless you need the settings.

ste-fu
  • 6,879
  • 3
  • 27
  • 46
  • 3
    When setProfileEnvironment="false" is set, where does it get the environment value from? Which user's environment? – Paul Michaels Dec 07 '16 at 08:01
  • @pm_2 That's a really good question - I couldn't find the answer with some googling. I guess it either doesn't load them, or uses the current server settings. Sorry not to be more help. – ste-fu Dec 07 '16 at 09:24
  • Hmm... I already had `setProfileEnvironment` turned off, but it's still using a timezone that's an hour off of the server default. And it's for a vendor application, so I can't just fix the code. – Joel Coehoorn Mar 18 '21 at 19:40
  • Weird daylight savings issue? – ste-fu Mar 18 '21 at 22:02
2

You can set the culture of your application via web.config or on page level. This should override the application pool user's culture.

have a look at this https://msdn.microsoft.com/en-us/library/bz9tc508(v=vs.140).aspx

Trekco
  • 1,246
  • 6
  • 17
  • The issue with that is the customer has requested it use the system's local so setting it in the page or web.config would not work if they decide to change the local. Is it possible to set the locale based on the system locale not the locale of the user running the AppPool? – Chris Ward Mar 19 '15 at 21:33
2

Your web site shouldn't rely on Server setup to work as intended for the locale. You should set the Thread.Culture and Thread.UICulture in your Global.asax file or in the web.config.

If you do it in your project, you protect yourself from Environment issues.

Doing it this way will also be easier to use different locales in different sites.

PhilDulac
  • 1,305
  • 20
  • 32
0

The best way to solve this is too create your own user account, assign this user to the application pool. You can then change this users locale by logging in as the user.

Make sure that this user has access to the web files

Have a look at this link

https://www.bluevalleytech.com/techtalk/blog/assigning-ntfs-folder-permission-to-iis7-application-pools.aspx

Trekco
  • 1,246
  • 6
  • 17
  • Unfortunatlly our customers will not allow us to create and login as users on their network so this will not be an option for us. – Chris Ward Mar 19 '15 at 12:16
  • then you need to set the culture in your web application have a look at this https://msdn.microsoft.com/en-us/library/bz9tc508(v=vs.140).aspx – Trekco Mar 19 '15 at 17:27
  • The issue with that is the customer has requested it use the system's local so setting it in the page or web.config would not work if they decide to change the local. Is it possible to set the locale based on the system locale not the locale of the user running the AppPool? – Chris Ward Mar 19 '15 at 21:33
0

You can programmatically change culture of your app by setting this in your Global.asax:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    Thread.CurrentThread.CurrentCulture = CultureInfo.CurrentCulture;
}

where CultureInfo.CurrentCulture will return your OS culture.

More info about this you can find in https://support.microsoft.com/pl-pl/kb/306162, detect os language from c#.

Community
  • 1
  • 1
Lesmian
  • 3,932
  • 1
  • 17
  • 28
  • But that's not the point, to manually handle the culture in code. The global.asx solution above is the way to go. Set and forget! – Fandango68 Dec 09 '16 at 01:11
  • @Fernando68 Ekhm... and how is setting culture in global.asax not setting it manually by code? And if you read my answer you would know that I suggest to set it in Global.asax... – Lesmian Dec 09 '16 at 06:42
  • Not sure I follow you, but my point was simply to change it once and move on. – Fandango68 Dec 13 '16 at 01:29
0

You don't want to use CultureInfo.CurrentCulture (this returns culture of current thread) but instead use CultureInfo.InstalledUICulture

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    Thread.CurrentThread.CurrentCulture = CultureInfo.InstalledUICulture;
    //sets the thread culture to OS language.
}
Gurpreet
  • 1,382
  • 11
  • 24