Given a username and password how do i impersonate that user and run some code as that user.
And by managed i mean without pinvokes or dllimports
All of the examples I've seen fail to take into account the fact that the logon type is not a one size fits all solution.
For example this will only work if the user you are impersonating has permission to logon to the target system. Not always the case when accessing a remote SQL Server box. LOGON32_LOGON_INTERACTIVE
NetworkClearText is the only one that works consistently for use with SQL Server connections. - No clear text does not mean it is passing credentials in an insecure manner.
When on a workgroup and you need to impersonate a domain user NewCredentials is the one that works. (not tested with SQL Server connections)