gpt4 book ai didi

asp.net-mvc - 当我们设置线程 CurrentCulture/CurrentUICulture 时,是否会影响 ASP.NET 中的多个用户?

转载 作者:行者123 更新时间:2023-12-02 08:51:12 26 4
gpt4 key购买 nike

当我们设置 CurrentCulture 和/或 CurrentUICulture 时,我们在当前线程上执行此操作,如下所示:


Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");<br/>
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");

这是否意味着我们可以影响 Web 应用程序的多个用户的区域性设置,因为他们的请求可能会重用池中的线程?

我正在开发一个 ASP.NET MVC 应用程序,其中每个用户都可以在他/她的帐户数据中指定自己的区域性设置。当用户登录时,将从数据库中检索区域性设置,并且必须将其设置为当前区域性。

我担心的是,在当前线程上设置当前区域性可能会影响重用该线程的另一个用户请求。读到这里我更担心:


ASP.NET not only uses a thread pool, but may switch threads during request processing.

最佳答案

洛基·洛特卡 blogged about this very question几年前 - 据报道 Scott Guthrie 告诉他这一点:

ASP.NET ensures that, even if theyswitch your thread, theCurrentPrincipal and cultureproperties from the original threadcarry forward to the new thread. Thisis automatic, and you don’t need toworry about losing those values. Whew!

However, thread-local storage doesn’t carry forward.

这篇文章包含更多有趣的 Material (他概述了 ASP.NET 切换线程的情况 - 至少截至 2006 年),绝对值得一读。不幸的是,Rocky 没有提供权威来源的链接。 Reflector 在这里也没有多大帮助,因为所有相关方法都在 native 调用中终止。

话虽如此,这是有道理的:API 强烈暗示当前的文化是跨上下文切换的,就像当前的主体一样,而且我从未见过 ASP.NET 与预期的行为相矛盾。

关于asp.net-mvc - 当我们设置线程 CurrentCulture/CurrentUICulture 时,是否会影响 ASP.NET 中的多个用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2863593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com