[英]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. 在IIS中创建应用程序池时,请为其指定名称。 You can then set the identity to ApplicationPoolIdentiy.
然后,您可以将标识设置为ApplicationPoolIdentiy。
Windows then creates this magic user you can't see. Windows然后创建这个你看不到的神奇用户。 Say the app pool name is MyTestAppPool so you would end up with a user called MyTestAppPool (IIS AppPool\\MyTestAppPool)
假设应用程序池名称是MyTestAppPool,那么最终会得到一个名为MyTestAppPool的用户(IIS AppPool \\ MyTestAppPool)
When this happens Windows uses the servers current locale. 发生这种情况时,Windows使用服务器当前区域设置。 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.
因此,当您的MyTestAppPool设置为US时,您的服务器将设置为UK。
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. 因此,当一个网站运行并且您需要在正确的区域设置中将某些内容格式化为货币时,由于AppPool而不是英国货币,您最终会使用美国货币。
Is there a way to change the AppPool user's locale? 有没有办法更改AppPool用户的区域设置?
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? 如果我需要在不同的语言环境中运行多个网站,如何在不创建apppool之前将AppPoolIdentity用户区域设置为其中每一个而不必将服务器更改为我想要的内容,该怎么办?
When you create and use an App Pool Identity, a "user" is created and there is a folder at C:\\Users\\AppPoolName
. 创建和使用应用程序池标识时,将创建“用户”,并在
C:\\Users\\AppPoolName
有一个文件夹。
In C:\\Windows\\System32\\inetsrv\\config\\applicationHost.config
there is an element which on my machine looks like this: 在
C:\\Windows\\System32\\inetsrv\\config\\applicationHost.config
有一个元素在我的机器上看起来像这样:
<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. 你应该能够通过检查加载
..\\Users\\AppPoolName\\NTUSER.DAT
的用户的HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\hivelist
来找出唯一的ID,然后将其与HKEY_USERS\\UnqiueId\\ControlPanel\\International\\Locale
的设置HKEY_USERS\\UnqiueId\\ControlPanel\\International\\Locale
设置。
It may just be simpler to set setProfileEnvironment="false"
unless you need the settings. 除非您需要设置,否则设置
setProfileEnvironment="false"
可能更简单。
You can set the culture of your application via web.config or on page level. 您可以通过web.config或页面级别设置应用程序的文化。 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 看看这个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. 您应该在Global.asax文件或web.config中设置
Thread.Culture
和Thread.UICulture
。
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 确保此用户可以访问Web文件
Have a look at this link 看看这个链接
https://www.bluevalleytech.com/techtalk/blog/assigning-ntfs-folder-permission-to-iis7-application-pools.aspx 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: 您可以通过在Global.asax中设置此项来以编程方式更改应用程序的文化:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CurrentCulture;
}
where CultureInfo.CurrentCulture
will return your OS culture. CultureInfo.CurrentCulture
将返回您的操作系统文化。
More info about this you can find in https://support.microsoft.com/pl-pl/kb/306162 , detect os language from c# . 有关这方面的更多信息, 请访问https://support.microsoft.com/pl-pl/kb/306162 , 从c#中检测os语言 。
You don't want to use CultureInfo.CurrentCulture (this returns culture of current thread) but instead use CultureInfo.InstalledUICulture 您不想使用CultureInfo.CurrentCulture(这会返回当前线程的文化),而是使用CultureInfo.InstalledUICulture
protected void Application_BeginRequest(Object sender, EventArgs e)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InstalledUICulture;
//sets the thread culture to OS language.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.