This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to read client m/c windows login id through JavaScript.  RSS feed

Ramesh Biradar
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can any one tell me how to read the client machine windows login id.

Here my requirnment is whenever client request for page, I have to read client's windows login id and I have to compare againest the database(server). If id exists then I should allow user to access the application. If id does not exists, then I have to open login page for authentication.

Can anyone help me to know how to get the client m/c windows login id.

Thanks in advance

Ramesh Biradar.
Ulf Dittmer
Posts: 42972
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

I'm fairly certain that JavaScript does not have access to this kind of information, because that would be a breach of privacy. Can't the resource be protected by requiring standard server-side measures, like HTTP authentication or NT Challenge/Response?
AilBala Subramanian
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear friends,

I am new to with C#.
My requirement is getting system login user id while page loading and displaying user detail based on fetched userid.
I have used the following methods in code behind part:

1. Request.UserHostName;
2. Request.ServerVariables["AUTH_USER"] ;
3. Request.ServerVariables["LOGON_USER"] ;
4. System.Web.HttpContext.Current.User.Identity.Name;
5. Environment.GetEnvironmentVariable("USERNAME").ToString();
6. User.Identity.Name
7. this.Request.LogonUserIdentity.Name;
8. System.Security.Principal.WindowsIdentity.GetCurrent().Name;
9. System.Environment.ExpandEnvironmentVariables("%username%");
10. dynamic wshell = Server.CreateObject("WScript.Shell");
string test = wshell.ExpandEnvironmentStrings("%username%");

Everything giving expected output. But after deploying that file in server and executing the deployed file it is giving blank outputs and server names. but not my expected output (user id).
I am suffering with this problem for the past 3 days. any idea... please...

since code behind part is not giving my expected output. I have used the below clientscript method in javascript:
function get_user_id() {
var wshShell = new ActiveXObject("WScript.Shell");
document.getElementById('hiddenfield').value = wshShell.ExpandEnvironmentStrings("%USERNAME%");
called this function in onload event of the body tag. I am getting user id in popup alert box.
string X = hiddenfield.value; // <-- looking empty
but in my code behind part it is still empty. while seeing it in debug mode my page load event in code behind part is executing first then only scripts are executing.

So, via this method also I can't achieve my target. I am so confused what to do. Please help me.... :-(
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!