Response.Redirect的不preserve HttpContext.Current.Items [英] Response.redirect does not preserve HttpContext.Current.Items

查看:149
本文介绍了Response.Redirect的不preserve HttpContext.Current.Items的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习有关的HttpContext ,并发现了

I was learning about the HttpContext and found out that

HttpContext对象将被新建成的给定每个请求
  到ASP.Net应用程序

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

现在,考虑这样一种情况,当我有两页。 WebForm1中和Webform2。在Form1,我写了下面提及code和重定向到窗体2。

Now, consider a case, when I have two pages. WebForm1 and Webform2. In Form1, I am writing the below mentioned code and redirects to form2.

HttpContext.Current.Items.Add("Key", "Value");

查询

当我用Server.Transfer的这个键依然存在,这是不是在使用的Response.Redirect的情况下

Query

When I use Server.Transfer this key persist and this is not the case while using Response.Redirect

Wnenever生成一个新的请求,则创建HttpCopntext对象。此外,Session是preserved。这是HttpContext的一部分。

Wnenever a new request is generated, HttpCopntext object is created. Moreover, Session is preserved. Which is part of HttpContext.

HttpContext.Current.Session

如果会话可以坚持,为什么不能 HttpContext.Current.Items 的Response.Redirect

If Session can persist, why can't HttpContext.Current.Items in Response.Redirect?

推荐答案

重定向生成一个新的的HttpContext 这就是为什么它的项目都将丢失 - 重定向有效地告诉浏览器中的下一个URL请求,并当它它失去触发重定向的previous请求的上下文

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.

会话跨请求(通常使用一个会话ID的Cookie给用户绑定在值在服务器上)仍然存在,因此是仍然可用。

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

这篇关于Response.Redirect的不preserve HttpContext.Current.Items的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆