No. They're entirely different things. HttpContext.User
is a ClaimsPrincipal
created via authentication of a specific user. System.Security.Principal.WindowsIdentity
is the principal used by the App Pool. As such, it will be a constant for the application, whereas HttpContext.User
is going to be the actual user making the request to your app, assuming they've authenticated.
I think where people get confused is when developing locally and using Windows Authentication. In that one specific scenario, the two will be same, because IIS Express is running under your local user account, which is of course, how you're also authenticated by Windows. In virtually every other situation they will be different, and frankly obvious that System.Security.Principal.WindowsIdentity
is not what you're looking for.
Now, as to why User.Identity.Name
is null, you likely are expecting to be authenticated by Windows, but have not enabled Windows Authentication for the app, meaning you are not actually logged in. Right-click your project(s), choose Properties, and then go to the Debug tab. At the bottom of the screen, make sure Enable Windows Authentication is checked. If you have any part of your site that does not require authorization, make sure Enable Anonymous Authentication is also checked, or you can uncheck it, you want to force all access to the site to be authorized.