在请求生命周期中,web.config“全球化”是在哪里?使用的部分?
我正在考虑在 ASP .NET 应用程序中使用“全球化”web.config 部分来提供应用于所有请求的默认区域性。在某些情况下,我们将在“AcquireRequestState”事件期间以编程方式覆盖此值,但我想知道“全球化”部分的“culture”和“uiCulture”属性将在请求生命周期的哪个阶段被覆盖应用于服务请求的线程。
我假设 System.Web 命名空间中有一些代码如下所示:
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(webConfigCulture);
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(webConfigUiCulture);
其中“webConfigCulture”和“webConfigUiCulture”代表 web.config 的全球化部分中“culture”和“uiCulture”的值。
有人知道这是在哪里发生的吗(例如什么请求/页面事件)?还是我离基地太远了?
I'm considering the use of the 'globalization' web.config section in our ASP .NET application to provide a default culture to be applied to all requests. In some cases, we'll be overriding this value programmaticly during the 'AcquireRequestState' event, but I'd like to know at what stage in the request life cycle the 'culture' and 'uiCulture' properties of the 'globalization' section will be applied to the thread servicing the request.
I'm assuming that there's some code in the System.Web namespace that looks like this:
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(webConfigCulture);
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(webConfigUiCulture);
Where 'webConfigCulture' and 'webConfigUiCulture' represent the values of the 'culture' and 'uiCulture' in the globalization section of the web.config.
Anyone know where this is happening (e.g. what request/page event)? Or am I way off base?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,区域性存储在 http 上下文中而不是线程中,并从那里复制到线程中。请求可以在页面周期内从一个线程移动到另一个线程,因此区域性必须遵循请求,而不是线程。
因此,在创建 http 上下文对象时应用区域性,这发生在页面周期的“开始”阶段,在
PreInit
事件之前。您可以在此处阅读更多信息:ASP.NET 页面生命周期概述
Altually, the culture is stored in the http context rather than the thread, and copied from there to the thread. A request can be moved from one thread to another over the page cycle, so the culture has to follow the request, not the thread.
So, the culture is applied when the http context object is created, which happens at "Start" stage of the page cycle, before the
PreInit
event.You can read more here: ASP.NET Page Life Cycle Overview