Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
hi
I need to know if there is any setting can be done on IIS or on Web.config, to read current logged on windows user by using java script on ASP.net .

On IIS :

I don't want to use windows authentication , because windows login window will be shown.

I know that javascript is run on client , so when I use the Anonymous Authentication , script bring blank, nothing came out !!.

Please If you have the solution share it here .


Thanks
Posted
Updated 16-Dec-15 23:17pm
v4

1 solution

First things first. It is not possible*

Browsers are not allowed to access such sensitive information. It will cause a huge security threat.

*- Now coming to the asterix.

The only way to get windows user info using javascript is using ActiveX. It will only work in internet explorer. So it is safe to say that there is no accepted way to do this globally.

If you still want to go ahead and get it through internet explorer, then here is the treat you are looking for,

JavaScript
<script language="javascript"> 
function GetUserName() 
{ 
var winShell= new ActiveXObject("WScript.Shell"); 
alert(winShell.ExpandEnvironmentStrings("%USERNAME%")); 
} 
</script>


Trying to get the user information using JavaScript is a feeble way. Just make a server call through ajax or which ever method you are comfortable with. Then pass on the retrieved user info to JavaScript and do whatever you requirement demands you to.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900