Session和HttpContext.Current.Session對象有什麼區別?Session和HttpContext.Current.Session之間的區別
回答
沒有區別。
Page.Session的getter返回上下文會話。
沒有。 Session
只是指向HttpContext.Current.Session
。
這裏有點晚,但這裏是我剛發現的東西。
@Phillipe Leybaert和@CSharpAtl都不正確。 HttpApplication
的Session
屬性展示不同於屬性HttpContext.Current.Session
的行爲。如果有一個可用,他們都會返回對同一個HttpSessionState
實例的引用。噹噹前請求沒有可用的HttpSessionState
實例時,它們的做法會有所不同。
並非所有HttpHandler
都提供會話狀態。爲此,HttpHandler
必須實施[一個或兩個?]標記接口IRequiresSessionState
或IReadOnlySessionState
。如果沒有會話可用,則返回null
。
的HttpApplication
的實施Session
屬性與消息Session state is not available in this context.
引發HttpException
而不是返回一個null
參考。
HttpHandler
沒有實現會話的一些示例是通常靜態資源(如圖像和CSS文件)的默認處理程序。在這種情況下(如在global.asax
事件處理程序中)對HttpApplication
的Session
屬性的任何引用都將導致引發HttpException
。
不用說,意想不到的HttpException
提供了一個WTF ?!如果你不期待它。
的HttpApplication
類的Session
性能,從而實現(從反射鏡):
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public HttpSessionState Session
{
get
{
HttpSessionState session = null;
if (this._session != null)
{
session = this._session;
}
else if (this._context != null)
{
session = this._context.Session;
}
if (session == null)
{
throw new HttpException(SR.GetString("Session_not_available"));
}
return session;
}
}
感謝您付出努力填寫更好的答案。 – nicodemus13 2011-05-26 10:19:59
- 1. ControllerContext.HttpContext.Session和HttpContext.Current.Session之間的區別是什麼
- 2. Laravel 4中的Input :: flash()和Session :: flash()之間的區別4
- 3. TensorFlow C++ API中ClientSession和Session之間的區別
- 4. Session.Add(「key」,value)和Session [「key」] = value之間有什麼區別?
- 5. '+ ='和'= +'之間的區別?
- 6. {!!之間的區別!!}和{{}}
- 7. ==和case之間的區別?
- 8. '#','%'和'$'之間的區別
- 9. | =和^ = css之間的區別
- 10. 「%〜dp0」和「。\」之間的區別?
- 11. .eq之間的區別。和==
- 12. ==和.equals()之間的區別?
- 13. `%in%`和`==`之間的區別
- 14. SPFile和PublishingPage類別之間的區別
- 15. System.Timers.Timer Enabled = true和.Start()之間的區別Enabled = true和.Start()之間的區別
- 16. NSthread和NStimer和NSNotifcation之間的區別?
- 17. Java和C#和.NET之間的區別
- 18. sys.log()和console.log()和console.error()之間的區別?
- 19. $ .ajax()和$ .get()和$ .load()之間的區別
- 20. javascript中的/ * * /和//之間的區別
- 21. python中的[]和[,,]之間的區別
- 22. QWidget的setStyleSheet和QApplication之間的區別
- 23. CKeditor的getHtml()和getData()之間的區別
- 24. make中的「$(shell ...)」和「$$(...)」之間的區別
- 25. C中的/ +和+之間的區別?
- 26. Alamofire的responseJSON和responseData之間的區別
- 27. WordPress的:site_id和blog_id之間的區別?
- 28. '|'之間的區別和 '+' 的位操作
- 29. 春季的/ **和/ *之間的區別
- 30. Satchmo的local_settings.py和settings.py之間的區別
這是值得澄清的是,當你說「會話」,你是指System.Web.UI.Page.Session 。 Session對象在ASP.NET頁面的上下文中可用。 – Llyle 2010-10-11 23:45:06