WindowsIdentity.RunImpersonated errors
Author: mriehmCreated Jan 24, 2022Updated Apr 11, 2022
Reading the WindowsIdentity.RunImpersonated examples in the AsyncGuidance, there appear to be two errors:
- Each of the delegates are defined as taking a
contextparameter. However,RunImpersonateddoes not take any delegate with parameters. It only takesActionorFunc<T>(Func<Task>orFunc<Task<T>>forRunImpersonatedAsync), so why is thiscontextparameter in the examples? - The first BAD example appears to be incorrect. It states: "This example tries to execute the query asynchronously, and then wait for it outside of the call to RunImpersonated. This will throw because the query might be executing outside of the impersonation context." However, that example code doesn't actually have any functional problem. In fact, it is semantically equivalent to the first GOOD example, which we can confirm by seeing that the supposedly BAD example matches the runtime implementation of the RunImpersonated method that is used in the first GOOD example.
Source: davidfowl/AspNetCoreDiagnosticScenarios