UserControl.Session和HttpContext.Current.Session之间的区别 [英] Difference between UserControl.Session and HttpContext.Current.Session

查看:62
本文介绍了UserControl.Session和HttpContext.Current.Session之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释一下UserControl.Session和HttpContext.Current.Session之间的区别。当我用Google搜索它时,有许多答案表明它们都是相同的。但是今天在调试我当前的项目时,我发现在执行response.redirect之后,UserControl.Session变为null,而HttpContext.Current.Session仍然存在。在usercontrol和页面之间处理会话的方式有什么区别吗?

Can anyone explain me the difference between UserControl.Session and HttpContext.Current.Session. When I googled it, there are many answers which state that both are same. But today while debugging my current project I have found that after response.redirect is executed the UserControl.Session is becoming null while HttpContext.Current.Session is still present. Is there any difference between the way session is handled between usercontrol and pages?

推荐答案

它们都是相同的,它们都引用相同的会话对象.HttpContext对象通常是在使用HttpHandlers时使用。当然你也可以在你自己的页面中使用它,但它都是一样的。



当你说Page.Session或简单的Session时,它间接指的是HttpContext.Current .Session。有关详细信息,请参阅以下内容:



UserControl.Session属性



HttpContext.Session Property
They both are same and they both refer to the same session object.HttpContext object is typically used when you are working with HttpHandlers. Ofcourse you can use it in your own page also, but its all the same.

When you say Page.Session or simply Session, its indirectly referring to HttpContext.Current.Session. For more details see these:

UserControl.Session Property

HttpContext.Session Property


检查以下链接。它回答了你的问题。



httpcontext.current.session vs sessionstate.httpsessionstate.usercontrol.session



另一个非常有用的链接:



在response.redirect之后丢失的激情变量



设置后不要重定向一个Session变量(或者做对了)
Check below link.It answered for your question.

httpcontext.current.session vs sessionstate.httpsessionstate.usercontrol.session

Another very useful links :

session variable lost after response.redirect

Don't redirect after setting a Session variable (or do it right)


这篇关于UserControl.Session和HttpContext.Current.Session之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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