Response.redirect does not preserve HttpContext.Current.Items

后端 未结 2 1427
暗喜
暗喜 2020-12-20 08:06

I was learning about the HttpContext and found out that

HttpContext object will be constructed newly for every request given to an ASP.

2条回答
  •  感动是毒
    2020-12-20 08:15

    I recommend to you to look with dotPeek at System.Web.dll, in particular at property HttpContext.Session that uses in getter HttpContext.Items["AspSession"] and at method SessionStateModule.InitStateStoreItem(...) (called in that getter) wich calls SessionStateUtility.AddHttpSessionStateToContext(...). You can see, that content of HttpSessionState collection is stored between requests in SessionStateStoreProviderBase implemented (InProc, Sql) object, more deeper in one word. Whereas HttpContext.Items hashtable is initialized at first get and dies between requests.

提交回复
热议问题