Click here to Skip to main content
15,918,617 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When an ASP.NET page loads, i want to log the windows account logged into the computer. I have tried
Environment.UserDomainName + "\" + Environment.UserName
but this returns the windows account that is HOSTING on the server.

I have also tried
still with no success.

Will any one guide me on how to get the username of the person logged into windows when an page loads!

One problem with getting the user name is that you have a dependency on the configuration in IIS. If your website is set up to run with Anonymous Access only, then you will not get the user. You need to change the settings to allow Integrated Windows Authentication to retrieve the user name.

In the page, you can use Page.User.Identity.Name.
Share this answer
Reiss 21-Jul-11 5:25am    
You can type faster than me ;)
Have you disabled anonymous mode in IIS

Have you set the application to autheticate the user details
<authentication mode="Windows"/>
  <allow users="*"/>

Have you used
Share this answer
Pete O'Hanlon 21-Jul-11 5:27am    
You typed more code in there than I did;). Have a 5 from me.
devenv.exe 21-Jul-11 5:39am    
@Reiss: the application requirements dictate that we stick with Forms Authentication, Will i only be able to achieve what i want to do only if i switch to Windows Authentication?. Switching from Forms to Windows authentication is really not applicable with this website application.

Reiss 21-Jul-11 5:55am    
EricCiz - if you are using Forms authentication, then can't you just store the username entered in the form for later use?
devenv.exe 21-Jul-11 7:00am    
@Reiss - but that would be the sql membership username, but for this particular requirement i need the windows username because some pages in application do not require signing in but i still want to know who was logged into windows when they loaded.

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