I See Sharp I See Sharp - 11 months ago 59
ASP.NET (C#) Question

How to get Current User who's accessing ASP.net app?

To get the current logged in user at the system I use this code:

string opl = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();


I work on an ASP.net app where I need this info. So I've put my app on a server and tried the code above and I get "Network Service" in the string opl. I need to know the current user of the PC who accesses my ASP.net app.

Any help is appreciated! Thank you in advance.

Answer Source

If you're using membership you can do: Membership.GetUser()

Your code is returning windows account which is assigned with ASP.NET.