I created a Blazor Server application (.Net core 3.1). The application uses Windows authentication. The application will need to access some Windows services like file sharing, and database with Integrated security etc. So it has the following impersonation code.
var identity = await IdentityProvider.GetIdentityAsync();
if (identity.IsAuthenticated && identity is WindowsIdentity wid)
{
return WindowsIdentity.RunImpersonated(wid.AccessToken, () =>
{
Fun1(....); // Should be called using the authentication of logged in user
});
The Fun1() should be called using the identity of the Windows users who are using the application, instead of the account which is used to running the website.
For example, the Identity of the application pool for my web site is MyDomain\UserX. And when a user MyDomain\UserY is using the website. I want the function Fun1() is impersonated under MyDomain\UserY instead of MyDomain\UserX.
I created a website on IIS, published the code, disabled anonymous authentication and enabled Windows Authentication. However, the function Fun1() is still called using the identity in the Application Pool? Should any settings in the Active directory be changed?