zl程序教程

您现在的位置是:首页 >  工具

当前栏目

global.asax Application_AcquireRequestState vs. Application_BeginRequest

vs application global
2023-09-11 14:14:17 时间

global.asax Application_AcquireRequestState vs. Application_BeginRequest

问题

what is the difference? I would like to implement Language dropdown selection in my app. So when a selected language is selected, a Thread culture would be set and page reloaded.

Like so:

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");

where should settings like above be processed? Application_AcquireRequestState or Application_BeginRequest?

thanks

 

回答1

It depends on the way you are saving your language across requests. If you are using a session to save your selected language in, you should use Application_AcquireRequestState, because since Application_BeginRequest is earlier in the life cycle, the session state object might not yet be available at this time.

 

回答2

Application_BeginRequest occurs earlier in the lifecycle and is the 'usual' place this goes.

http://msdn.microsoft.com/en-us/library/ms178473%28v=VS.100%29.aspx

 

Working with the ASP.NET Global.asax file

they’re triggered in the following order:

  • Application_BeginRequest
  • Application_AuthenticateRequest
  • Application_AuthorizeRequest
  • Application_ResolveRequestCache
  • Application_AcquireRequestState
  • Application_PreRequestHandlerExecute
  • Application_PreSendRequestHeaders
  • Application_PreSendRequestContent
  • <<code is executed>>
  • Application_PostRequestHandlerExecute
  • Application_ReleaseRequestState
  • Application_UpdateRequestCache
  • Application_EndRequest

A common use of some of these events is
security.