user1201228
user1201228

Reputation: 11

How can i get the Logged in user Name of Client machine

How can i get the LoggedIn in user Name of Client machine

without client providing the useid and password... (wjen the users visits the page i need to get In which user Id he/she loggedIn)

I tried

string clientMachineName;
clientMachineName = (Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName);
Response.Write(clientMachineName);

Upvotes: 0

Views: 5298

Answers (4)

user153923
user153923

Reputation:

It seems ServerVariables have been depreciated for C# in some instances.

If so, you'll need to do it this way:

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

If you really want to use ServerVariables, keep in mind they are CaSe Sensitive in C#. The correct casing is almost always UPPER, and here is the list of them:

List of ServerVariables

Upvotes: 0

Tamil
Tamil

Reputation: 68

You can use Request.LogonUserIdentity for getting client details.

Response.Write(Request.LogonUserIdentity.Name);

Upvotes: 0

M.Babcock
M.Babcock

Reputation: 18965

If you're in a domain environment you could enable Windows Authentication which will allow the users to bypass explicitly logging on in favor of NTLM authentication. IE and Chrome work well with this out of the box, FF has a config setting for it.

EDIT

If you only care about browsers/OSs that support ActiveX then you can get it using Javascript with specific ActiveX privileges (from here):

<script type="text/javascript"> 
<!-- 
var WinNetwork = new ActiveXObject("WScript.Network"); 
alert(WinNetwork.UserName); 
//--> 
</script>

Upvotes: 2

Sanjay Goswami
Sanjay Goswami

Reputation: 1386

Try this Might be its work as per your requirement

Request.ServerVariables["LOGON_USER"]

if Request.ServerVariables("LOGON_USER") Returns Empty String in ASP.NET Microsoft Guidline for that

Upvotes: 0

Related Questions