I have an ASP.net application running in an windows intranet environment. I have a requirement to perform certain database updates as the currently logged in user.
IIS/server info:
- IIS version 10
- Windows server 2019
- ASP.net web forms application
- .NET 4.7
- Windows authentication enabled
- Impersonation and anonymous authentication are disabled
- The app pool uses integrated pipeline
- The app pool runs with a domain service account for it's identity, which has rights to access other resources as needed.
Other details:
- All of my database connection strings are set such that integrated security=true
- in active directory, have configured constrained delegation between the web server and the SQL server, allowing MSSQLSvc : 1433 and MSSQLSvc (no port)
- The domain service account is a member of the local administrators group on the web server (for testing purposes only)
When i perform the database updates that need to be done as the currently logged in user, i impersonate them in this way:
var windowsIdentity = User.Identity as WindowsIdentity;
WindowsIdentity.RunImpersonated(windowsIdentity.AccessToken, () =>
{
// perform database update
});
This throws an exception -
System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'
If i change the app pool identity to use AppPoolIdentity (the default app pool identity) the impersonation works properly.
Why does this impersonation work with AppPoolIdentity, but not my domain service account?