Search code examples
c#asp.net-mvc-5

Temporary disabling of impersonation in MVC5


I have app level impersonation with a special account which allows for Database Access and other functions.

But for one specific operation (Reading files from the user's PC), i need to disable the app level impersonation.

Is there a way I can use "WindowsImpersonationContext" to disable app impersonation for a section and reactivate itself as soon as the code is done... (Preferably through a using statement).


Solution

  • So, I was able to solve it.

    Thanks to: Can I turn off impersonation just in a couple instances

    I used:

    using (var impersonationContext = WindowsIdentity.Impersonate(IntPtr.Zero))