global.asax Application_AcquireRequestState vs. Application_BeginRequest
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.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-05-30 Why is HttpContext.Current null during the Session_End event?
2018-05-30 kentico7中设置site的default page
2018-05-30 Analyzing with SonarScanner for MSBuild
2017-05-30 插入css样式表的三种方法