开发者

My.User.Name vs. My.User.CurrentPrincipal.Identity.Name

开发者 https://www.devze.com 2023-01-15 02:00 出处:网络
I\'ve found that both My.User.Name and My.User.CurrentPrincipal.Identity.Name both return the Windows l开发者_StackOverflow社区ogin ID of the user logged in to the PC. However, is there a difference b

I've found that both My.User.Name and My.User.CurrentPrincipal.Identity.Name both return the Windows l开发者_StackOverflow社区ogin ID of the user logged in to the PC. However, is there a difference between the two? Will there ever be a case where they won't return the same value?


The information on the My.User MSDN page has the best summary of these values and when they differ

  • http://msdn.microsoft.com/en-us/library/a3da82hw(VS.80).aspx

In summary though. The biggest difference occurs between Windows and Web Applications.

For Windows applications, this property provides the same functionality as the CurrentPrincipal property. For Web applications, this property provides the same functionality as the User property of the object returned by the Current property.


If you are in the context of a System.Web.UI.Page, then:

  • Me.User returns Me.Context.User;
  • Me.Context returns HttpContext.Current

So they are indeed the same thing.

Oops! Read that a bit too quickly. My is a "magic shortcut" to some common contextual objects, and User is one of them. It is still the same as the expanded form.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号