简体   繁体   中英

How do you set the IIS Application Pool Identity User Locale when it's set to ApplicationPoolIdentity

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?

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.

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

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.

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

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# .

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.
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM