asp.netangulariisactive-directorywindows-server-2022

How can I get the client username from the Active Directory after I published on IIS


I have an Angular frontend and ASP.NET backend, I published the site on IIS 10, I also created a Windows Server 2022 Virtual Machine in Hyper-V. Right now I can access the site from the external PC, but I don't want to use login prompt in chrome.

I just need the actual Windows username from the client side. On the backend I enabled anonymous authentication, on the frontend there is windows authentication. I tried to swap these settings and then from the backend I tried to read the username, but the backend runs on the server, not on the client PC.


Solution

  • You will need to use Windows Authentication, which will give you the username in the backend in HttpContext.Current.User.Identity.Name. Then, from there, you can insert the username (or whatever other information you need) into your frontend code.

    To prevent the browser from prompting for credentials, you need to add the URL to the Trusted Sites in the Windows Internet Options on each client computer. This can be done by Group Policy. That will tell Chrome and Edge to send the user credentials automatically. If your organization uses Firefox, it has its own setting for this.