Softawy 3ala tool
How to get Windows Login credentials using C#.Net , ASP.Net
one of the most famous topics is how we can know the current user credential like
user name, Groups, Authentication Type (I hope to find a way to know password
)
check this code
Console.WriteLine("AuthenticationType =" + WindowsIdentity.GetCurrent().AuthenticationType); Console.WriteLine("Name ="+WindowsIdentity.GetCurrent().Name); Console.WriteLine("Groups :"); foreach (IdentityReference ir in WindowsIdentity.GetCurrent().Groups) { Console.WriteLine(ir.Translate(typeof(NTAccount)).ToString()); }
and this a another way to get Windows Identity
WindowsPrincipal p = Thread.CurrentPrincipal as WindowsPrincipal; (p.Identity as WindowsIdentity)
and for ASP.Net
HttpContext.Current.User.Identity
for more information
Windows Principal , Windows Identity
Nice post, Hatim! Excellent explanation, and straight to the point.
I would add one “caveat” about using WindowsIdentity.GetCurrent() to get user credentials in an application. That function doesn’t necessarily return information about the logged in user all the time. Rather, it returns the ID of the user that’s currently running the app thread.
Where I’ve seen issues happen with using WindowsIdentity.GetCurrent to get the user’s credentials is if a developer tries to use WindowsIdentity.GetCurrent to get the logged in user on a web application. In the application that I saw, it returned the NT Authority\Network Service (ID running the thread) rather than the actual user on the application.
I was very happy that you mentioned in your post that ASP.NET app users should use HttpContext.Current.User to get the login information about the user on the application.
Great information! I’ve been looking for something like this for a while now. Thanks!
Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.
just send email to me
htotisum@gmail.com
free ebook…
[...]Hatim AlSum Personal Blog | How to get Windows Login credentials using C#.Net , ASP.Net[...]…