Search code examples
c#.net-4.0authorizationwindows-authentication

get current windows user in webapp


I am using string appNetworkUserId = WindowsIdentity.GetCurrent().Name; to get the current user of my web application. It works when I'm running the machine locally. I get domain\my name, but when I run the app on my dev server I get NT AUTHORITY\NETWORK SERVICE instead of the user who is accessing the website.

How can I get the user name of the visitor to my webapp?

I'm using .net 4.0 and C#


Solution

  • Here's what I ended up using. And this works.

     System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent();
     string[] a = Context.User.Identity.Name.Split('\\');
     string appNetworkUserId = Context.User.Identity.Name.ToString();