Once the HTTP page handler class is fully identified, the ASP.NET run time calls the handler's ProcessRequest method to process the request. ... (it) begins by calling the method FrameworkInitialize, which builds the controls tree for the page. The method is a protected and virtual member of the TemplateControl class - the class from which Page itself derives. Any dynamically generated handler for an .aspx resource overrides FrameworkInitialize. In this method, the whole control tree for the page is built.
Next, ProcessRequest makes the page transit various phases: initialization, loading of view state information and postback data, loading of the page's user code and execution of postback server-side events. After that, the page enters in rendering mode: the updated view state is collected; the HTML code is generated and then sent to the output console. Finally, the page is unloaded and the request is considered completely served.
方法二。在PreRequestHandlerExecute中設定你所需要的文化。參見HttpApplication類的線上協助:
An application executes events that are handled by modules or user code that is defined in the Global.asax file in the following sequence:
1. BeginRequest
2. AuthenticateRequest
3. PostAuthenticateRequest
4. AuthorizeRequest
5. PostAuthorizeRequest
6. ResolveRequestCache
An event handler (a page corresponding to the request URL) is created at this point.
7. PostResolveRequestCache
8. PostMapRequestHandler
9. AcquireRequestState
10. PostAcquireRequestState
11. PreRequestHandlerExecute
The event handler is executed.
12. PostRequestHandlerExecute
13. ...
我試過 BeginRequest, 但是不行。我想原因是因為Page.Request在此之後才被建立或賦值,所以在BeginRequest中設定的文化會被覆蓋了。直到 10. PostAcquireRequestState,才被準備好,只有在此之後我們才可以設定所需要的文化。
11和12之間的 "The event handler is executed."就應該是整個頁面的生命週期的處理了。方法一使用InitializeCulture就是在這裡。