How to get Windows user name when identity impersonate=”true” in asp.net?

With <authentication mode=”Windows”/> in your application and Anonymous access enabled in IIS, you will see the following results: System.Environment.UserName: Computer Name Page.User.Identity.Name: Blank System.Security.Principal.WindowsIdentity.GetCurrent().Name: Computer Name With <authentication mode=”Windows”/> in your application, and ‘Anonymous access’ disabled and only ‘Integrated Windows Authentication’ in IIS, you will see the following results: System.Environment.UserName: ASPNET (user account used to … Read more

How to use LogonUser properly to impersonate domain user from workgroup client

Very few posts suggest using LOGON_TYPE_NEW_CREDENTIALS instead of LOGON_TYPE_NETWORK or LOGON_TYPE_INTERACTIVE. I had an impersonation issue with one machine connected to a domain and one not, and this fixed it. The last code snippet in this post suggests that impersonating across a forest does work, but it doesn’t specifically say anything about trust being set … Read more

How do you do Impersonation in .NET?

“Impersonation” in the .NET space generally means running code under a specific user account. It is a somewhat separate concept than getting access to that user account via a username and password, although these two ideas pair together frequently. Impersonation The APIs for impersonation are provided in .NET via the System.Security.Principal namespace: Newer code should … Read more

Run as a different user without a password from an elevated prompt in Windows

I use this all the time. It does take entering a credential the first time it’s used (and when the password changes) but that’s it. runas /user:yourusernamehere /savecred “Your Executable Here” If you save this command as part of a bat file you can create a shortcut that will launch this with administrative rights using … Read more