Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have developed an app which contains windows authentication.so it does not need any login.Directly it should fetch the system's username from which it has logged in.

I have used System.Environment.UserName which gives me correct username ,when i run at my localhost.
But when i upload it on iis it gives me "Network Services" as Username.


Priyanka.
Posted

Environment.UserName [^] Gets the user name of the person who is currently logged on to the Windows operating system - it's the identification of the security credentials currently executing the code.

What you want is HttpContext.User[^] which will be the security credentials for the user executing the HTTP request.
 
Share this answer
 
Comments
StianSandberg 13-Aug-12 5:51am    
Correct 5'd
RaoPriya 17-Aug-12 0:47am    
what i want is when user accesses the website from his/her machine then the username from which he has logged into his/her machine.In iis i have unchecked the anonymous users and ticked on windows integration in security settings. the o/p which i get is the username where the website is actually hosted from wherever(other machine) i access the website..
Dylan Morley 17-Aug-12 3:31am    
Sure, so HttpContext.User is still what you will use to get the details.

Make sure that you set the authentication mode to Windows in your web.config as well - http://msdn.microsoft.com/en-us/library/ff647405.aspx
C#
HttpContext.Current.User.Identity.Name
 
Share this answer
 
try...
C#
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
 
Share this answer
 
Comments
kk2014 16-Aug-12 9:01am    
she had also tried it but it is not working....

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