Context.User.Identity.Name vs HttpContext.Current.User.Identity.Name

*爱你&永不变心* 提交于 2019-12-06 09:04:40

问题


In aspx.net, what is the difference between

Context.User.Identity.Name 

and

HttpContext.Current.User.Identity.Name

Im currently using the Context.User.Identity.Name from a masterpage and are having trouble with user identitys beeing mixed up (user A sees user B data). Could this be the source of the problem?


回答1:


They are identical. Context has a reference to the current HttpContext which is the same as HttpContext.Current. So, I don't think this is causing the problem that you are having.




回答2:


As far as i know the two methods are identical because

Context 

is the same as

HttpContext.Current



回答3:


There is no difference in the context of a Page, because Page.Context returns the current HttpContext.

HttpContext.Current is a static method that returns the HttpContext associated with the calling thread (may return null) Page.Context is a reference set to same object as HttpContext.Current, but is a direct reference, no internal lookup required.



来源:https://stackoverflow.com/questions/6426357/context-user-identity-name-vs-httpcontext-current-user-identity-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!