Reputation: 162
I am trying to get the current windows user of the computer where my ASP.NET Core application is being accessed.
I have tried this on my solution.
System.Security.Principal.WindowsIdentity.GetCurrent().Name
On my machine, when running the application locally it works fine and it returns me my username but when i deploy the project, it returns me the name of the server.
Is what i am asking possible at all?
Upvotes: 0
Views: 741
Reputation: 239440
That's not how you do it. What you're doing returns the principal the application is running under. Locally, that's obviously you, because it's running under your account. However, on the server, it's the App Pool user. In either case, it's not the user accessing the application; it was only coincidental that locally, the user accessing the application and the account the application is running under were the same.
What you're looking for is Windows Authentication, which you need to specifically turn on (see: Configure Windows Authentication in ASP.NET Core). Then, you access the user as you would always access the user, regardless of authentication scheme: HttpContext.User
.
Upvotes: 2