0

When I use System.Environment.UserName or httpcontext.current.... etc all are returning "System" as user as my site is hosted in system privileged. Tried WMI but this comes up as empty.

ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT UserName FROM Win32_ComputerSystem");
ManagementObjectCollection collection = searcher.Get();
WinUser = (string)collection.Cast<ManagementBaseObject>().First()["UserName"];

I am using Basic Authentication and Anonymous authentication is turned off. any idea?

3 Answers 3

1

It is inherently impossible to find out the logged-in user on the client computer, especially if the client computer is an iPad.

You can get the username received from basic auth using HttpContext.Current.User.

Sign up to request clarification or add additional context in comments.

9 Comments

this is intranet app, can be accessed from network only. user logs into network using their win. credentials and then browses site on intranet which requires another separate win login HttpContext.Current.User is logging name through which user logged into intranet application instead of windows log name of machine.
@user570715: Your question is completely impossible, unless you use Windows Authentication with Active Directory.
we use windows authentication. this site is hosted in our network on internal server say server "a". I log into my network using my credentials say user "abc" now i type server address on IE to browse this site which ask to me enter credentials again because i have enabled win. basic authentication on IIS so i enter credentials of common win. a/c of network say user "tester". now i want to write to db that "win user abc has accessed application using tester a/c"
What Can't I do? Can't retrieve name for both users? Currently When I log to db this is how msg is displayed - "win user ServiceUser has accessed application using tester a/c" Only part I am missing is win. username(abc), I am able to get username of person who is accessing application in this case - "tester"
I'm not sure what you're saying. HTTP connections do not include windows credentials.
|
1

Unless this is an intranet application and you're using Windows Authentication, there is no way to get this information without first prompting the user for their credentials.

Assuming that you are using Windows Authentication and your users are entering their network credentials when prompted, you should be able to get the username like this:

string userName = Page.User.Identity.Name;

Comments

0

Try HttpContext.Current.Request.LogonUserIdentity

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.