Categories c# windows-server-2008

How to get current user who’s accessing an ASP.NET application?

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 application where I need this information. So I’ve put my application 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 application.

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

Your code is returning the Windows account which is assigned with ASP.NET.

Additional Info Edit:
You will want to include System.Web.Security

using System.Web.Security