Click here to Skip to main content
16,016,760 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to get the user name of system its works properly in local host but when use this cade in server it return blank.

What I have tried:

i want to get the user name of system its works properly in local host but when use this cade in server it return blank.
Posted
Updated 29-May-16 21:17pm
Comments
Kassim Shaikh 30-May-16 2:14am    
Did you try the below System.Environment.UserName ? I think it work's for Asp.net too

You will require Windows Authentication enabled for the website in IIS.
 
Share this answer
 
v2
The problem is that you will always fetch the username of the Server, not the Client - it looks like it works on your development machine because it runs on the same computer and IIS local host executes under your user ID. C# code always executes on the Server, never on the client - which can basically only run Javascript.
When you release to production, the code retrieves the username for the server running IIS, which is likely to be blank as it's not running as a "real" user.
You cannot retrieve the login username for a client in C#, and you can't get it in all browsers in javascript.
 
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