System.Web.HttpContext.Current.User.Identity.Name Vs System.Environment.UserName in ASP.NET

后端 未结 2 981
走了就别回头了
走了就别回头了 2020-11-27 21:29

What is the difference between System.Web.HttpContext.Current.User.Identity.Name and System.Environment.UserName in the context of a ASP.Net Web Ap

相关标签:
2条回答
  • 2020-11-27 22:07

    Description

    System.Web.HttpContext.Current.User.Identity.Name

    Gets or sets security information for the current HTTP request. (The Name of the Logged in user on your Website)

    System.Environment.UserName

    Gets the user name of the person who is currently logged on to the Windows operating system.

    More Information

    • MSDN - HttpContext.User Property
    • MSDN - Environment.UserName Property
    0 讨论(0)
  • 2020-11-27 22:09

    System.Environment.UserName returns the identity under which the app pool that hosts your web app is running. If you're using Windows authentication and impersonation then it will be the actual user's name, however in all cases you're better off using the information provided by the HTTP context. There is no performance hit either way.

    0 讨论(0)
提交回复
热议问题