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

2020-07-23 05:26发布

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?

3条回答
我想做一个坏孩纸
2楼-- · 2020-07-23 05:34

As far as i know the two methods are identical because

Context 

is the same as

HttpContext.Current
查看更多
来,给爷笑一个
3楼-- · 2020-07-23 05:51

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.

查看更多
够拽才男人
4楼-- · 2020-07-23 05:55

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.

查看更多
登录 后发表回答