ExtensionsDirectoryServicesImpersonate Method |
Namespace: Cauldron
public static WindowsImpersonationContext Impersonate( this PrincipalContext principalContext, string username, string password, LogonType logonType )
Exception | Condition |
---|---|
ArgumentNullException | username is null |
ArgumentNullException | password is null |
ArgumentException | username is empty |
ArgumentException | password is empty |
using (var context = new PrincipalContext(ContextType.Domain)) { context.Impersonate("billgates", "superSafePassword!!!!1111", LogonType.Network); // Do anything in the context of the user 'billgates' this.database.DeleteAll(); }