0

So I'm trying to get a logged in user's User.Identity.Name. My computer is on a domain and I am logging in using domain credentials.

I've implemented the following service into Startup.cs:

services
   .AddAuthentication(NegotiateDefaults.AuthenticationScheme)
   .AddNegotiate();

I also added the following lines:

app.UseAuthentication(); 
app.UseAuthorization();

I then use the following within an API controller:

[HttpGet]
        public String Get()
        {
            return User.Identity.Name;
        }

When I launch the application, it will not accept my logged in user credentials. It will only accept my other domain account that has local administrator access. Is this expected behavior? How can I fix this?

I remember this working fine in VS2017 and Asp.Net. I'm currently using VS2019 with Core 3.1

Thanks

Izacch
  • 383
  • 3
  • 10

1 Answers1

0

You configure your application like you are supposed to do when you use Kestrel as the host. However, perhaps you are launching your application with IIS? To configure Windows Authentication correctly in IIS you need to perform some additional steps which are detailed in Configure Windows Authentication in ASP.NET Core. I suggest that you carefully check that you have performed all the steps required for hosting in either IIS, Kestrel or HTTP.sys detailed in this guide.

Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
  • Hey Martin, thanks for your reply. I am debugging using IIS Express. I actually tried opening an older ASP.NET application (built in VS2017) I worked on previously, in VS2019, and when debugging, it has the exact same problem. Maybe this problem I'm facing is related to VS2019 or perhaps even my local user profile. Any ideas? – Izacch Sep 29 '20 at 08:51
  • To use Windows Authentication in IIS you need specific entries in your `web.config` file as described in https://learn.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-3.1&tabs=visual-studio#iisiis-express. When using IIS Express in Visual Studio you set them in project properties (select web project, press F4). Also see https://stackoverflow.com/questions/24194941/windows-authentication-not-working-in-iis-express-debugging-with-visual-studio/38403757. – Martin Liversage Sep 29 '20 at 09:39