I have written a Blazor Server App and deployed it to IIS.
Inside the app I would like to access the database as the Windows Active Directory user using the site, not the IIS user.
This code works, but it always returns the IIS user:
System.Security.Principal.WindowsIdentity identity =
System.Security.Principal.WindowsIdentity.GetCurrent();
I have found and tried all the variants shown below, from my internet search, but none return the User ID from AD accessing the website. I am not an IIS admin - maybe the magic is in there? Appreciate any help.
// .name is always null
var httpUser = HttpContextAccessor.HttpContext.User.Identity;
// principal user is null
var principalUser = Thread.CurrentPrincipal; //.Identity.Name;
// Is this supposed to impersonate the AD User?
web.config
<system.web>
<identity impersonate="true"/>
</system.web>
// This may only affect debugging??
- Project Properties
- Debug/Launch Profiles
- Disabled Anonymous Auth
- Enabled Windows Auth
- Debug/Launch Profiles
// Browsed through authState and see nothing resembling the AD User Id
var authState = await AuthenticationStateProvider
.GetAuthenticationStateAsync();