Response.redirect does not preserve HttpContext.Current.Items

后端 未结 2 1426
暗喜
暗喜 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:11

    The redirect generates a new HttpContext which is why the items in it are lost - the redirect effectively tells the browser the next URL to request, and when it does it loses the context of the previous request that triggered the redirect.

    The session persists across requests (typically using a sessionID cookie to tie the user to values on the server), and is thus still available.

提交回复
热议问题